@atlaskit/editor-plugin-block-menu 9.0.18 → 9.1.0
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 +17 -0
- package/dist/cjs/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -5
- package/dist/cjs/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
- package/dist/cjs/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
- package/dist/cjs/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +4 -1
- package/dist/cjs/editor-commands/transformNode.js +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -6
- package/dist/es2019/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
- package/dist/es2019/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +3 -0
- package/dist/es2019/editor-commands/transformNode.js +1 -1
- package/dist/esm/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -6
- package/dist/esm/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
- package/dist/esm/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
- package/dist/esm/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
- package/dist/esm/editor-commands/transform-node-utils/utils.js +3 -0
- package/dist/esm/editor-commands/transformNode.js +1 -1
- package/dist/types/blockMenuPluginType.d.ts +1 -1
- package/dist/types/editor-commands/selection.d.ts +1 -1
- package/dist/types/editor-commands/transform-node-utils/{flattenStep.d.ts → steps/flattenStep.d.ts} +1 -1
- package/dist/types/editor-commands/transform-node-utils/{unwrapExpandStep.d.ts → steps/unwrapExpandStep.d.ts} +1 -1
- package/dist/types/editor-commands/transform-node-utils/{unwrapStep.d.ts → steps/unwrapStep.d.ts} +1 -1
- package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/wrapIntoListStep.d.ts +1 -1
- package/dist/types/editor-commands/transform-node-utils/{wrapStep.d.ts → steps/wrapStep.d.ts} +1 -1
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +1 -0
- package/dist/types/editor-commands/transformNode.d.ts +1 -1
- package/dist/{types-ts4.5/editor-commands/transforms → types/editor-commands}/types.d.ts +0 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/selection.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{flattenStep.d.ts → steps/flattenStep.d.ts} +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapExpandStep.d.ts → steps/unwrapExpandStep.d.ts} +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapStep.d.ts → steps/unwrapStep.d.ts} +1 -1
- package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/wrapIntoListStep.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{wrapStep.d.ts → steps/wrapStep.d.ts} +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +1 -0
- package/dist/types-ts4.5/editor-commands/transformNode.d.ts +1 -1
- package/dist/{types/editor-commands/transforms → types-ts4.5/editor-commands}/types.d.ts +0 -3
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/editor-commands/transforms/block-transforms.js +0 -55
- package/dist/cjs/editor-commands/transforms/container-transforms.js +0 -448
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +0 -39
- package/dist/cjs/editor-commands/transforms/layout/utils.js +0 -355
- package/dist/cjs/editor-commands/transforms/layout-transforms.js +0 -79
- package/dist/cjs/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -97
- package/dist/cjs/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -59
- package/dist/cjs/editor-commands/transforms/list/transformToTaskList.js +0 -44
- package/dist/cjs/editor-commands/transforms/list-transforms.js +0 -161
- package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +0 -77
- package/dist/cjs/editor-commands/transforms/utils.js +0 -260
- package/dist/es2019/editor-commands/transforms/block-transforms.js +0 -58
- package/dist/es2019/editor-commands/transforms/container-transforms.js +0 -449
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +0 -33
- package/dist/es2019/editor-commands/transforms/layout/utils.js +0 -334
- package/dist/es2019/editor-commands/transforms/layout-transforms.js +0 -75
- package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -93
- package/dist/es2019/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -47
- package/dist/es2019/editor-commands/transforms/list/transformToTaskList.js +0 -38
- package/dist/es2019/editor-commands/transforms/list-transforms.js +0 -168
- package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +0 -76
- package/dist/es2019/editor-commands/transforms/utils.js +0 -248
- package/dist/esm/editor-commands/transforms/block-transforms.js +0 -50
- package/dist/esm/editor-commands/transforms/container-transforms.js +0 -441
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +0 -33
- package/dist/esm/editor-commands/transforms/layout/utils.js +0 -348
- package/dist/esm/editor-commands/transforms/layout-transforms.js +0 -72
- package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -90
- package/dist/esm/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -53
- package/dist/esm/editor-commands/transforms/list/transformToTaskList.js +0 -37
- package/dist/esm/editor-commands/transforms/list-transforms.js +0 -155
- package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +0 -72
- package/dist/esm/editor-commands/transforms/utils.js +0 -253
- package/dist/types/editor-commands/transforms/block-transforms.d.ts +0 -5
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +0 -20
- package/dist/types/editor-commands/transforms/inline-node-transforms.d.ts +0 -6
- package/dist/types/editor-commands/transforms/layout/utils.d.ts +0 -5
- package/dist/types/editor-commands/transforms/layout-transforms.d.ts +0 -6
- package/dist/types/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +0 -3
- package/dist/types/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +0 -3
- package/dist/types/editor-commands/transforms/list/transformToTaskList.d.ts +0 -10
- package/dist/types/editor-commands/transforms/list-transforms.d.ts +0 -23
- package/dist/types/editor-commands/transforms/transformNodeToTargetType.d.ts +0 -14
- package/dist/types/editor-commands/transforms/utils.d.ts +0 -45
- package/dist/types-ts4.5/editor-commands/transforms/block-transforms.d.ts +0 -5
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +0 -20
- package/dist/types-ts4.5/editor-commands/transforms/inline-node-transforms.d.ts +0 -6
- package/dist/types-ts4.5/editor-commands/transforms/layout/utils.d.ts +0 -5
- package/dist/types-ts4.5/editor-commands/transforms/layout-transforms.d.ts +0 -6
- package/dist/types-ts4.5/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +0 -3
- package/dist/types-ts4.5/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +0 -3
- package/dist/types-ts4.5/editor-commands/transforms/list/transformToTaskList.d.ts +0 -10
- package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +0 -23
- package/dist/types-ts4.5/editor-commands/transforms/transformNodeToTargetType.d.ts +0 -14
- package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +0 -45
- /package/dist/cjs/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
- /package/dist/cjs/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
- /package/dist/cjs/editor-commands/{transforms/types.js → types.js} +0 -0
- /package/dist/es2019/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
- /package/dist/es2019/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
- /package/dist/es2019/editor-commands/{transforms/types.js → types.js} +0 -0
- /package/dist/esm/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
- /package/dist/esm/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
- /package/dist/esm/editor-commands/{transforms/types.js → types.js} +0 -0
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { transformListRecursively, isBulletOrOrderedList, isTaskList, getSupportedListTypesSet } from '@atlaskit/editor-common/transforms';
|
|
3
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { getInlineNodeTextContent } from '../inline-node-transforms';
|
|
6
|
-
import { getContentSupportChecker, isBlockNode, isBlockNodeForExtraction, isBlockNodeType, isContainerNode, isContainerNodeType, isHeadingOrParagraphNode, isListNode, isListNodeType } from '../utils';
|
|
7
|
-
export var unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(context, finalTargetNodeType) {
|
|
8
|
-
var tr = context.tr,
|
|
9
|
-
sourceNode = context.sourceNode,
|
|
10
|
-
targetNodeType = context.targetNodeType,
|
|
11
|
-
targetAttrs = context.targetAttrs;
|
|
12
|
-
var schema = tr.doc.type.schema || {};
|
|
13
|
-
var isValid = getContentSupportChecker(finalTargetNodeType);
|
|
14
|
-
var createTextNode = function createTextNode(node) {
|
|
15
|
-
var isTextNode = node.type.name === 'text';
|
|
16
|
-
var nodeToTransform = node;
|
|
17
|
-
if (isContainerNodeType(finalTargetNodeType) || isListNodeType(finalTargetNodeType)) {
|
|
18
|
-
nodeToTransform = node.mark(node.marks.filter(function (mark) {
|
|
19
|
-
return !['alignment', 'indentation'].includes(mark.type.name);
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
if (isValid(nodeToTransform) && !isTextNode) {
|
|
23
|
-
return nodeToTransform;
|
|
24
|
-
}
|
|
25
|
-
return targetNodeType.createChecked(targetAttrs, isTextNode ? nodeToTransform : nodeToTransform.content, nodeToTransform.marks);
|
|
26
|
-
};
|
|
27
|
-
if (isBlockNode(sourceNode)) {
|
|
28
|
-
// code block acts like a container, we need to unwrap it
|
|
29
|
-
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
30
|
-
var textNodes = sourceNode.textContent.split('\n').map(function (line) {
|
|
31
|
-
return targetNodeType.createChecked(undefined, line ? schema.text(line) : null);
|
|
32
|
-
});
|
|
33
|
-
return textNodes;
|
|
34
|
-
}
|
|
35
|
-
return [createTextNode(sourceNode)];
|
|
36
|
-
}
|
|
37
|
-
if (isContainerNode(sourceNode)) {
|
|
38
|
-
var _sourceNode$attrs;
|
|
39
|
-
var containerNodes = [];
|
|
40
|
-
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs = sourceNode.attrs) !== null && _sourceNode$attrs !== void 0 && _sourceNode$attrs.title) {
|
|
41
|
-
containerNodes.push(createTextNode(schema.text(sourceNode.attrs.title)));
|
|
42
|
-
}
|
|
43
|
-
sourceNode.content.forEach(function (childNode) {
|
|
44
|
-
if (isHeadingOrParagraphNode(childNode)) {
|
|
45
|
-
containerNodes.push(createTextNode(childNode));
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
containerNodes.push(childNode);
|
|
49
|
-
});
|
|
50
|
-
return containerNodes;
|
|
51
|
-
}
|
|
52
|
-
if (isListNode(sourceNode)) {
|
|
53
|
-
if (isBlockNodeType(finalTargetNodeType)) {
|
|
54
|
-
if (sourceNode.type.name === 'taskList') {
|
|
55
|
-
var taskItemsResult = findChildrenByType(sourceNode, schema.nodes.taskItem);
|
|
56
|
-
var taskItems = taskItemsResult.map(function (item) {
|
|
57
|
-
return item.node;
|
|
58
|
-
});
|
|
59
|
-
var taskItemFragments = taskItems.map(function (taskItem) {
|
|
60
|
-
return taskItem.content;
|
|
61
|
-
});
|
|
62
|
-
return taskItemFragments.map(function (fragment) {
|
|
63
|
-
return targetNodeType.createChecked(targetAttrs, fragment.content);
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
var paragraphs = findChildrenByType(sourceNode, schema.nodes.paragraph);
|
|
67
|
-
var paragraphNodes = paragraphs.map(function (paragraph) {
|
|
68
|
-
return paragraph.node;
|
|
69
|
-
});
|
|
70
|
-
if (targetNodeType === schema.nodes.heading) {
|
|
71
|
-
return paragraphNodes.map(function (paragraphNode) {
|
|
72
|
-
return targetNodeType.createChecked(targetAttrs, paragraphNode.content);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return paragraphNodes;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return [sourceNode];
|
|
79
|
-
}
|
|
80
|
-
return [sourceNode];
|
|
81
|
-
};
|
|
82
|
-
var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
83
|
-
var newNodes = [];
|
|
84
|
-
var addToNewNodes = function addToNewNodes(content) {
|
|
85
|
-
if (newNodes.length === 0) {
|
|
86
|
-
newNodes.push({
|
|
87
|
-
canBeTransformed: true,
|
|
88
|
-
content: content
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
// Check if last node can also be transformed, if yes then append content
|
|
92
|
-
var lastItem = newNodes[newNodes.length - 1];
|
|
93
|
-
if (lastItem.canBeTransformed) {
|
|
94
|
-
newNodes[newNodes.length - 1] = {
|
|
95
|
-
content: [].concat(_toConsumableArray(lastItem.content), _toConsumableArray(content)),
|
|
96
|
-
canBeTransformed: true
|
|
97
|
-
};
|
|
98
|
-
} else {
|
|
99
|
-
newNodes.push({
|
|
100
|
-
content: content,
|
|
101
|
-
canBeTransformed: true
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
nodes.forEach(function (node) {
|
|
107
|
-
if (node.isTextblock) {
|
|
108
|
-
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
109
|
-
addToNewNodes([inlineTextContent]);
|
|
110
|
-
} else if (isListNode(node)) {
|
|
111
|
-
var textContent = [];
|
|
112
|
-
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
113
|
-
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
114
|
-
return item.node;
|
|
115
|
-
});
|
|
116
|
-
listItems.forEach(function (listItem) {
|
|
117
|
-
if (listItem.type === schema.nodes.taskItem) {
|
|
118
|
-
var _inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem)).inlineTextContent;
|
|
119
|
-
textContent.push(_inlineTextContent);
|
|
120
|
-
} else {
|
|
121
|
-
var _inlineTextContent2 = getInlineNodeTextContent(listItem.content).inlineTextContent;
|
|
122
|
-
textContent.push(_inlineTextContent2);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
addToNewNodes(textContent);
|
|
126
|
-
} else {
|
|
127
|
-
// If not text block or list node, then cannot be transformed
|
|
128
|
-
newNodes.push({
|
|
129
|
-
canBeTransformed: false,
|
|
130
|
-
content: node
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return newNodes.map(function (_ref) {
|
|
135
|
-
var canBeTransformed = _ref.canBeTransformed,
|
|
136
|
-
content = _ref.content;
|
|
137
|
-
if (canBeTransformed) {
|
|
138
|
-
var text = content.join('\n');
|
|
139
|
-
if (text === '') {
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
return schema.nodes.codeBlock.createChecked(null, schema.text(text));
|
|
143
|
-
} else {
|
|
144
|
-
return content;
|
|
145
|
-
}
|
|
146
|
-
}).filter(Boolean);
|
|
147
|
-
};
|
|
148
|
-
var transformToBlockNode = function transformToBlockNode(nodes, targetNodeType, schema) {
|
|
149
|
-
if (targetNodeType === schema.nodes.codeBlock) {
|
|
150
|
-
return transformToCodeBlock(nodes, schema);
|
|
151
|
-
}
|
|
152
|
-
var newNodes = [];
|
|
153
|
-
nodes.forEach(function (node) {
|
|
154
|
-
if (isListNode(node)) {
|
|
155
|
-
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
156
|
-
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
157
|
-
return item.node;
|
|
158
|
-
});
|
|
159
|
-
listItems.forEach(function (listItem) {
|
|
160
|
-
if (listItem.type === schema.nodes.taskItem) {
|
|
161
|
-
var inlineContent = _toConsumableArray(listItem.content.content);
|
|
162
|
-
if (inlineContent.length > 0) {
|
|
163
|
-
newNodes.push(targetNodeType.createChecked(null, inlineContent));
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
listItem.forEach(function (child) {
|
|
167
|
-
if (isHeadingOrParagraphNode(child)) {
|
|
168
|
-
newNodes.push(targetNodeType.createChecked(null, _toConsumableArray(child.content.content)));
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
} else {
|
|
174
|
-
newNodes.push(node);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
return newNodes;
|
|
178
|
-
};
|
|
179
|
-
var transformToContainerNode = function transformToContainerNode(nodes, targetNodeType) {
|
|
180
|
-
var newNodes = [];
|
|
181
|
-
var isNodeValid = getContentSupportChecker(targetNodeType);
|
|
182
|
-
nodes.forEach(function (node) {
|
|
183
|
-
// If the node is not supported then we append as is
|
|
184
|
-
if (isBlockNodeForExtraction(node)) {
|
|
185
|
-
newNodes.push({
|
|
186
|
-
node: node,
|
|
187
|
-
canBeTransformed: false
|
|
188
|
-
});
|
|
189
|
-
} else {
|
|
190
|
-
var isSameNodeType = node.type === targetNodeType;
|
|
191
|
-
|
|
192
|
-
// If the node is not valid and not the same type, we cannot transform it
|
|
193
|
-
if (!isNodeValid(node) && !isSameNodeType) {
|
|
194
|
-
newNodes.push({
|
|
195
|
-
node: node,
|
|
196
|
-
canBeTransformed: false
|
|
197
|
-
});
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
var _nodes = isSameNodeType ? node.content.content : [node];
|
|
201
|
-
if (newNodes.length === 0) {
|
|
202
|
-
newNodes.push({
|
|
203
|
-
node: _nodes,
|
|
204
|
-
canBeTransformed: true
|
|
205
|
-
});
|
|
206
|
-
} else {
|
|
207
|
-
var lastItem = newNodes[newNodes.length - 1];
|
|
208
|
-
if (lastItem.canBeTransformed) {
|
|
209
|
-
newNodes[newNodes.length - 1] = {
|
|
210
|
-
node: [].concat(_toConsumableArray(lastItem.node), _toConsumableArray(_nodes)),
|
|
211
|
-
canBeTransformed: true
|
|
212
|
-
};
|
|
213
|
-
} else {
|
|
214
|
-
newNodes.push({
|
|
215
|
-
node: _nodes,
|
|
216
|
-
canBeTransformed: true
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
return newNodes.map(function (_ref2) {
|
|
223
|
-
var node = _ref2.node,
|
|
224
|
-
canBeTransformed = _ref2.canBeTransformed;
|
|
225
|
-
if (canBeTransformed) {
|
|
226
|
-
return targetNodeType.createChecked(null, Fragment.fromArray(node));
|
|
227
|
-
} else {
|
|
228
|
-
return node;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
export var transformToListNode = function transformToListNode(nodes, targetNodeType, schema) {
|
|
233
|
-
var isTargetTask = isTaskList(targetNodeType);
|
|
234
|
-
var listItems = [];
|
|
235
|
-
var listItemType = isTargetTask ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
236
|
-
var unsupportedContent = [];
|
|
237
|
-
var onhandleUnsupportedContent = function onhandleUnsupportedContent(content) {
|
|
238
|
-
unsupportedContent.push(content);
|
|
239
|
-
};
|
|
240
|
-
var isValid = getContentSupportChecker(listItemType);
|
|
241
|
-
nodes.forEach(function (node) {
|
|
242
|
-
// Append unsupported nodes as is
|
|
243
|
-
if (isBlockNodeForExtraction(node)) {
|
|
244
|
-
listItems.push({
|
|
245
|
-
canBeTransformed: false,
|
|
246
|
-
node: node
|
|
247
|
-
});
|
|
248
|
-
} else {
|
|
249
|
-
var newListItems;
|
|
250
|
-
|
|
251
|
-
// If the node is a list, we may need to transform it
|
|
252
|
-
if (isListNode(node)) {
|
|
253
|
-
var isSourceBulletOrOrdered = isBulletOrOrderedList(node.type);
|
|
254
|
-
var _isTargetTask = isTaskList(targetNodeType);
|
|
255
|
-
var isSourceTask = isTaskList(node.type);
|
|
256
|
-
var isTargetBulletOrOrdered = isBulletOrOrderedList(targetNodeType);
|
|
257
|
-
var supportedListTypes = getSupportedListTypesSet(schema.nodes);
|
|
258
|
-
if (node.type === targetNodeType) {
|
|
259
|
-
// For the same list type, we can keep the structure
|
|
260
|
-
newListItems = node.content.content;
|
|
261
|
-
} else {
|
|
262
|
-
var newList = transformListRecursively({
|
|
263
|
-
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
264
|
-
isSourceTask: isSourceTask,
|
|
265
|
-
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
266
|
-
isTargetTask: _isTargetTask,
|
|
267
|
-
listNode: node,
|
|
268
|
-
schema: schema,
|
|
269
|
-
supportedListTypes: supportedListTypes,
|
|
270
|
-
targetNodeType: targetNodeType
|
|
271
|
-
}, onhandleUnsupportedContent);
|
|
272
|
-
newListItems = _toConsumableArray(newList.content.content);
|
|
273
|
-
}
|
|
274
|
-
} else if (isHeadingOrParagraphNode(node) || isValid(node)) {
|
|
275
|
-
if (isTargetTask) {
|
|
276
|
-
var inlineContent = _toConsumableArray(node.content.content);
|
|
277
|
-
if (inlineContent.length > 0) {
|
|
278
|
-
newListItems = [listItemType.create(null, inlineContent)];
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
newListItems = [listItemType.create(null, node)];
|
|
282
|
-
}
|
|
283
|
-
} else if (!isValid(node)) {
|
|
284
|
-
listItems.push({
|
|
285
|
-
canBeTransformed: false,
|
|
286
|
-
node: node
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
if (newListItems) {
|
|
290
|
-
if (listItems.length === 0) {
|
|
291
|
-
listItems.push({
|
|
292
|
-
canBeTransformed: true,
|
|
293
|
-
node: newListItems
|
|
294
|
-
});
|
|
295
|
-
} else {
|
|
296
|
-
var lastItem = listItems[listItems.length - 1];
|
|
297
|
-
if (lastItem.canBeTransformed) {
|
|
298
|
-
listItems[listItems.length - 1] = {
|
|
299
|
-
node: [].concat(_toConsumableArray(lastItem.node), _toConsumableArray(newListItems)),
|
|
300
|
-
canBeTransformed: true
|
|
301
|
-
};
|
|
302
|
-
} else {
|
|
303
|
-
listItems.push({
|
|
304
|
-
node: newListItems,
|
|
305
|
-
canBeTransformed: true
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
return [].concat(_toConsumableArray(listItems.map(function (_ref3) {
|
|
313
|
-
var node = _ref3.node,
|
|
314
|
-
canBeTransformed = _ref3.canBeTransformed;
|
|
315
|
-
if (canBeTransformed) {
|
|
316
|
-
return targetNodeType.createChecked(null, Fragment.fromArray(node));
|
|
317
|
-
} else {
|
|
318
|
-
return node;
|
|
319
|
-
}
|
|
320
|
-
})), unsupportedContent);
|
|
321
|
-
};
|
|
322
|
-
export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema, targetAttrs) {
|
|
323
|
-
if (nodes.length === 1 && nodes[0].content.size === 0 && !isContainerNodeType(targetNodeType)) {
|
|
324
|
-
if (isBlockNodeType(targetNodeType)) {
|
|
325
|
-
if (['heading', 'paragraph'].includes(targetNodeType.name)) {
|
|
326
|
-
return [targetNodeType.createChecked(targetAttrs)];
|
|
327
|
-
}
|
|
328
|
-
if (targetNodeType.name === 'codeBlock') {
|
|
329
|
-
return [targetNodeType.createChecked()];
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (isListNodeType(targetNodeType)) {
|
|
333
|
-
var listItem = isTaskList(targetNodeType) ? schema.nodes.taskItem.createChecked() : schema.nodes.listItem.createChecked(null, schema.nodes.paragraph.createChecked());
|
|
334
|
-
return [targetNodeType.createChecked(null, listItem)];
|
|
335
|
-
}
|
|
336
|
-
return nodes;
|
|
337
|
-
}
|
|
338
|
-
if (isBlockNodeType(targetNodeType)) {
|
|
339
|
-
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
340
|
-
}
|
|
341
|
-
if (isContainerNodeType(targetNodeType)) {
|
|
342
|
-
return transformToContainerNode(nodes, targetNodeType);
|
|
343
|
-
}
|
|
344
|
-
if (isListNodeType(targetNodeType)) {
|
|
345
|
-
return transformToListNode(nodes, targetNodeType, schema);
|
|
346
|
-
}
|
|
347
|
-
return [];
|
|
348
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { DEFAULT_TWO_COLUMN_LAYOUT_COLUMN_WIDTH } from '@atlaskit/editor-common/styles';
|
|
3
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { convertUnwrappedLayoutContent, unwrapLayoutNodesToTextNodes } from './layout/utils';
|
|
5
|
-
import { getMarksWithBreakout, isHeadingOrParagraphNode } from './utils';
|
|
6
|
-
export var createDefaultLayoutSection = function createDefaultLayoutSection(schema, content, marks) {
|
|
7
|
-
var _schema$nodes = schema.nodes,
|
|
8
|
-
layoutSection = _schema$nodes.layoutSection,
|
|
9
|
-
layoutColumn = _schema$nodes.layoutColumn,
|
|
10
|
-
paragraph = _schema$nodes.paragraph;
|
|
11
|
-
var layoutContent = Fragment.fromArray([layoutColumn.createChecked({
|
|
12
|
-
width: DEFAULT_TWO_COLUMN_LAYOUT_COLUMN_WIDTH
|
|
13
|
-
}, content), layoutColumn.create({
|
|
14
|
-
width: DEFAULT_TWO_COLUMN_LAYOUT_COLUMN_WIDTH
|
|
15
|
-
}, paragraph.createAndFill())]);
|
|
16
|
-
return layoutSection.createChecked(undefined, layoutContent, marks);
|
|
17
|
-
};
|
|
18
|
-
export var convertToLayout = function convertToLayout(context) {
|
|
19
|
-
var tr = context.tr,
|
|
20
|
-
sourceNode = context.sourceNode,
|
|
21
|
-
sourcePos = context.sourcePos;
|
|
22
|
-
var content = sourceNode.mark(sourceNode.marks.filter(function (mark) {
|
|
23
|
-
return mark.type.name !== 'breakout';
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
// Layout supports breakout mark that can have width attribute
|
|
27
|
-
// When other nodes with breakout (codeBlock and expand) are converted to a layout, the layout should get width of original node
|
|
28
|
-
var marks = getMarksWithBreakout(sourceNode, tr.doc.type.schema.nodes.layoutSection);
|
|
29
|
-
var layoutSectionNode = createDefaultLayoutSection(tr.doc.type.schema, content, marks);
|
|
30
|
-
if (isHeadingOrParagraphNode(sourceNode)) {
|
|
31
|
-
// -1 to fix when sourceNode is the last node in the document, unable to convert to layout
|
|
32
|
-
tr.replaceRangeWith(sourcePos > 0 ? sourcePos - 1 : sourcePos, sourcePos + sourceNode.nodeSize - 1, layoutSectionNode);
|
|
33
|
-
} else {
|
|
34
|
-
tr.replaceRangeWith(sourcePos, sourcePos + sourceNode.nodeSize, layoutSectionNode);
|
|
35
|
-
}
|
|
36
|
-
return tr;
|
|
37
|
-
};
|
|
38
|
-
export var transformLayoutNode = function transformLayoutNode(context) {
|
|
39
|
-
var tr = context.tr,
|
|
40
|
-
sourceNode = context.sourceNode,
|
|
41
|
-
targetNodeType = context.targetNodeType,
|
|
42
|
-
sourcePos = context.sourcePos,
|
|
43
|
-
targetAttrs = context.targetAttrs;
|
|
44
|
-
var schema = tr.doc.type.schema || {};
|
|
45
|
-
var _ref = schema.nodes || {},
|
|
46
|
-
layoutSection = _ref.layoutSection,
|
|
47
|
-
layoutColumn = _ref.layoutColumn,
|
|
48
|
-
paragraph = _ref.paragraph,
|
|
49
|
-
heading = _ref.heading;
|
|
50
|
-
var layoutColumnNodes = [];
|
|
51
|
-
var targetTextNodeType = targetNodeType === heading ? heading : paragraph;
|
|
52
|
-
sourceNode.children.forEach(function (child) {
|
|
53
|
-
if (child.type === layoutColumn) {
|
|
54
|
-
var unwrappedContent = [];
|
|
55
|
-
child.content.forEach(function (node) {
|
|
56
|
-
// Unwrap all nodes and convert to text nodes
|
|
57
|
-
var context = {
|
|
58
|
-
tr: tr,
|
|
59
|
-
sourceNode: node,
|
|
60
|
-
targetNodeType: targetTextNodeType,
|
|
61
|
-
sourcePos: 0,
|
|
62
|
-
targetAttrs: targetAttrs
|
|
63
|
-
};
|
|
64
|
-
var newContent = unwrapLayoutNodesToTextNodes(context, targetNodeType);
|
|
65
|
-
unwrappedContent.push.apply(unwrappedContent, _toConsumableArray(newContent));
|
|
66
|
-
});
|
|
67
|
-
var newColumnContent = convertUnwrappedLayoutContent(unwrappedContent, targetNodeType, schema, targetAttrs);
|
|
68
|
-
layoutColumnNodes.push(layoutColumn.createChecked(child.attrs, Fragment.fromArray(newColumnContent), child.marks));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return tr.replaceRangeWith(sourcePos, sourcePos + sourceNode.nodeSize, layoutSection.createChecked(sourceNode.attrs, Fragment.fromArray(layoutColumnNodes), sourceNode.marks));
|
|
72
|
-
};
|
package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { getInlineNodeTextContent } from '../inline-node-transforms';
|
|
5
|
-
import { getContentSupportChecker, isListNode } from '../utils';
|
|
6
|
-
export var transformOrderedUnorderedListToBlockNodes = function transformOrderedUnorderedListToBlockNodes(context) {
|
|
7
|
-
var tr = context.tr,
|
|
8
|
-
targetNodeType = context.targetNodeType,
|
|
9
|
-
targetAttrs = context.targetAttrs,
|
|
10
|
-
sourceNode = context.sourceNode,
|
|
11
|
-
sourcePos = context.sourcePos;
|
|
12
|
-
var selection = tr.selection;
|
|
13
|
-
var schema = selection.$from.doc.type.schema;
|
|
14
|
-
var targetNodes = [];
|
|
15
|
-
// find all list items inside the list node
|
|
16
|
-
var listItems = findChildrenByType(sourceNode, schema.nodes.listItem);
|
|
17
|
-
var textContent = [];
|
|
18
|
-
var flushTextContent = function flushTextContent() {
|
|
19
|
-
if (targetNodeType !== schema.nodes.codeBlock) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (textContent.length > 0) {
|
|
23
|
-
var inlineText = textContent.join('\n');
|
|
24
|
-
targetNodes.push(schema.nodes.codeBlock.createChecked({}, inlineText !== '' ? schema.text(inlineText) : null));
|
|
25
|
-
textContent = [];
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
listItems.forEach(function (listItem) {
|
|
29
|
-
// Convert paragraphs to headings if target is heading
|
|
30
|
-
var content = listItem.node.content.content;
|
|
31
|
-
content.forEach(function (node) {
|
|
32
|
-
var isValid = getContentSupportChecker(targetNodeType)(node);
|
|
33
|
-
if (isListNode(node)) {
|
|
34
|
-
// Skip nested lists as it will return listItems that we will deal with separately
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Deal with the case where targetNode and node are both codeBlocks, then append text content
|
|
39
|
-
if (targetNodeType === schema.nodes.codeBlock && node.type === schema.nodes.codeBlock) {
|
|
40
|
-
var inlineContent = node.textContent;
|
|
41
|
-
textContent = [].concat(_toConsumableArray(textContent), [inlineContent]);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// If the node is not valid for the target container,
|
|
46
|
-
// flush any existing text content if target is codeBlock
|
|
47
|
-
// and extract the node without any conversion
|
|
48
|
-
if (!isValid && !node.isTextblock) {
|
|
49
|
-
flushTextContent();
|
|
50
|
-
targetNodes.push(node);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// If the target is codeBlock, accumulate text content
|
|
55
|
-
if (targetNodeType === schema.nodes.codeBlock) {
|
|
56
|
-
var _inlineContent = getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
57
|
-
textContent = [].concat(_toConsumableArray(textContent), [_inlineContent]);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Convert codeblocks to block nodes
|
|
62
|
-
if (node.type === schema.nodes.codeBlock) {
|
|
63
|
-
var _targetAttrs$level;
|
|
64
|
-
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-split-replace -- Ignored via go/ees017 (to be fixed)
|
|
65
|
-
var _textContent = node.textContent.split('\n');
|
|
66
|
-
var attributes = targetNodeType === schema.nodes.heading ? {
|
|
67
|
-
level: (_targetAttrs$level = targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) !== null && _targetAttrs$level !== void 0 ? _targetAttrs$level : 1
|
|
68
|
-
} : null;
|
|
69
|
-
_textContent.forEach(function (textLine) {
|
|
70
|
-
targetNodes.push(targetNodeType.createChecked(attributes, textLine ? schema.text(textLine) : null));
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
75
|
-
var targetHeadingLevel = targetAttrs.level;
|
|
76
|
-
targetNodes.push(schema.nodes.heading.createChecked({
|
|
77
|
-
level: targetHeadingLevel
|
|
78
|
-
}, node.content));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
targetNodes.push(node);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
flushTextContent();
|
|
85
|
-
var fragment = Fragment.fromArray(targetNodes);
|
|
86
|
-
var slice = new Slice(fragment, 0, 0);
|
|
87
|
-
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
88
|
-
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
89
|
-
return tr;
|
|
90
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
-
export var transformTaskListToBlockNodes = function transformTaskListToBlockNodes(context) {
|
|
4
|
-
var tr = context.tr,
|
|
5
|
-
targetNodeType = context.targetNodeType,
|
|
6
|
-
targetAttrs = context.targetAttrs,
|
|
7
|
-
sourceNode = context.sourceNode,
|
|
8
|
-
sourcePos = context.sourcePos;
|
|
9
|
-
var selection = tr.selection;
|
|
10
|
-
var schema = selection.$from.doc.type.schema;
|
|
11
|
-
var taskItemsResult = findChildrenByType(sourceNode, schema.nodes.taskItem);
|
|
12
|
-
var taskItems = taskItemsResult.map(function (item) {
|
|
13
|
-
return item.node;
|
|
14
|
-
});
|
|
15
|
-
var taskItemFragments = taskItems.map(function (taskItem) {
|
|
16
|
-
return taskItem.content;
|
|
17
|
-
});
|
|
18
|
-
var targetNodes = [];
|
|
19
|
-
|
|
20
|
-
// Convert fragments to headings if target is heading
|
|
21
|
-
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
22
|
-
// convert the fragments to headings
|
|
23
|
-
var targetHeadingLevel = targetAttrs.level;
|
|
24
|
-
targetNodes = taskItemFragments.map(function (fragment) {
|
|
25
|
-
return schema.nodes.heading.createChecked({
|
|
26
|
-
level: targetHeadingLevel
|
|
27
|
-
}, fragment.content);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Convert fragments to paragraphs if target is paragraphs
|
|
32
|
-
if (targetNodeType === schema.nodes.paragraph) {
|
|
33
|
-
// convert the fragments to paragraphs
|
|
34
|
-
targetNodes = taskItemFragments.map(function (fragment) {
|
|
35
|
-
return schema.nodes.paragraph.createChecked({}, fragment.content);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Convert fragments to code block if target is code block
|
|
40
|
-
if (targetNodeType === schema.nodes.codeBlock) {
|
|
41
|
-
// convert the fragments to one code block
|
|
42
|
-
var codeBlockContent = taskItemFragments.map(function (fragment) {
|
|
43
|
-
return fragment.textBetween(0, fragment.size, '\n');
|
|
44
|
-
}).join('\n');
|
|
45
|
-
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Replace the task list node with the new content in the transaction
|
|
49
|
-
var slice = new Slice(Fragment.fromArray(targetNodes), 0, 0);
|
|
50
|
-
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
51
|
-
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
52
|
-
return tr;
|
|
53
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
/**
|
|
3
|
-
* Transform selection to task list
|
|
4
|
-
* Handles the special structure where taskItem contains text directly (no paragraph wrapper)
|
|
5
|
-
*/
|
|
6
|
-
export var transformToTaskList = function transformToTaskList(tr, range, targetNodeType, targetAttrs, nodes) {
|
|
7
|
-
try {
|
|
8
|
-
var taskItem = nodes.taskItem;
|
|
9
|
-
var listItems = [];
|
|
10
|
-
|
|
11
|
-
// Process each block in the range
|
|
12
|
-
tr.doc.nodesBetween(range.start, range.end, function (node) {
|
|
13
|
-
if (node.isBlock) {
|
|
14
|
-
// For block nodes like paragraphs, directly use their inline content
|
|
15
|
-
var inlineContent = _toConsumableArray(node.content.content);
|
|
16
|
-
if (inlineContent.length > 0) {
|
|
17
|
-
// Create task item with inline content directly
|
|
18
|
-
var listItem = taskItem.create(targetAttrs, inlineContent);
|
|
19
|
-
listItems.push(listItem);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return false; // Don't traverse into children
|
|
23
|
-
});
|
|
24
|
-
if (listItems.length === 0) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Create the new task list
|
|
29
|
-
var newList = targetNodeType.create(targetAttrs, listItems);
|
|
30
|
-
|
|
31
|
-
// Replace the range with the new list
|
|
32
|
-
tr.replaceWith(range.start, range.end, newList);
|
|
33
|
-
return tr;
|
|
34
|
-
} catch (_unused) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
};
|