@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.
Files changed (106) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -5
  3. package/dist/cjs/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
  4. package/dist/cjs/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
  5. package/dist/cjs/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
  6. package/dist/cjs/editor-commands/transform-node-utils/utils.js +4 -1
  7. package/dist/cjs/editor-commands/transformNode.js +1 -1
  8. package/dist/es2019/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -6
  9. package/dist/es2019/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
  10. package/dist/es2019/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
  11. package/dist/es2019/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
  12. package/dist/es2019/editor-commands/transform-node-utils/utils.js +3 -0
  13. package/dist/es2019/editor-commands/transformNode.js +1 -1
  14. package/dist/esm/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +5 -6
  15. package/dist/esm/editor-commands/transform-node-utils/{unwrapExpandStep.js → steps/unwrapExpandStep.js} +1 -1
  16. package/dist/esm/editor-commands/transform-node-utils/{wrapIntoListStep.js → steps/wrapIntoListStep.js} +2 -2
  17. package/dist/esm/editor-commands/transform-node-utils/{wrapStep.js → steps/wrapStep.js} +2 -2
  18. package/dist/esm/editor-commands/transform-node-utils/utils.js +3 -0
  19. package/dist/esm/editor-commands/transformNode.js +1 -1
  20. package/dist/types/blockMenuPluginType.d.ts +1 -1
  21. package/dist/types/editor-commands/selection.d.ts +1 -1
  22. package/dist/types/editor-commands/transform-node-utils/{flattenStep.d.ts → steps/flattenStep.d.ts} +1 -1
  23. package/dist/types/editor-commands/transform-node-utils/{unwrapExpandStep.d.ts → steps/unwrapExpandStep.d.ts} +1 -1
  24. package/dist/types/editor-commands/transform-node-utils/{unwrapStep.d.ts → steps/unwrapStep.d.ts} +1 -1
  25. package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/wrapIntoListStep.d.ts +1 -1
  26. package/dist/types/editor-commands/transform-node-utils/{wrapStep.d.ts → steps/wrapStep.d.ts} +1 -1
  27. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +1 -0
  28. package/dist/types/editor-commands/transformNode.d.ts +1 -1
  29. package/dist/{types-ts4.5/editor-commands/transforms → types/editor-commands}/types.d.ts +0 -3
  30. package/dist/types/index.d.ts +1 -1
  31. package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -1
  32. package/dist/types-ts4.5/editor-commands/selection.d.ts +1 -1
  33. package/dist/types-ts4.5/editor-commands/transform-node-utils/{flattenStep.d.ts → steps/flattenStep.d.ts} +1 -1
  34. package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapExpandStep.d.ts → steps/unwrapExpandStep.d.ts} +1 -1
  35. package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapStep.d.ts → steps/unwrapStep.d.ts} +1 -1
  36. package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/wrapIntoListStep.d.ts +1 -1
  37. package/dist/types-ts4.5/editor-commands/transform-node-utils/{wrapStep.d.ts → steps/wrapStep.d.ts} +1 -1
  38. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +1 -0
  39. package/dist/types-ts4.5/editor-commands/transformNode.d.ts +1 -1
  40. package/dist/{types/editor-commands/transforms → types-ts4.5/editor-commands}/types.d.ts +0 -3
  41. package/dist/types-ts4.5/index.d.ts +1 -1
  42. package/package.json +4 -4
  43. package/dist/cjs/editor-commands/transforms/block-transforms.js +0 -55
  44. package/dist/cjs/editor-commands/transforms/container-transforms.js +0 -448
  45. package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +0 -39
  46. package/dist/cjs/editor-commands/transforms/layout/utils.js +0 -355
  47. package/dist/cjs/editor-commands/transforms/layout-transforms.js +0 -79
  48. package/dist/cjs/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -97
  49. package/dist/cjs/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -59
  50. package/dist/cjs/editor-commands/transforms/list/transformToTaskList.js +0 -44
  51. package/dist/cjs/editor-commands/transforms/list-transforms.js +0 -161
  52. package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +0 -77
  53. package/dist/cjs/editor-commands/transforms/utils.js +0 -260
  54. package/dist/es2019/editor-commands/transforms/block-transforms.js +0 -58
  55. package/dist/es2019/editor-commands/transforms/container-transforms.js +0 -449
  56. package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +0 -33
  57. package/dist/es2019/editor-commands/transforms/layout/utils.js +0 -334
  58. package/dist/es2019/editor-commands/transforms/layout-transforms.js +0 -75
  59. package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -93
  60. package/dist/es2019/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -47
  61. package/dist/es2019/editor-commands/transforms/list/transformToTaskList.js +0 -38
  62. package/dist/es2019/editor-commands/transforms/list-transforms.js +0 -168
  63. package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +0 -76
  64. package/dist/es2019/editor-commands/transforms/utils.js +0 -248
  65. package/dist/esm/editor-commands/transforms/block-transforms.js +0 -50
  66. package/dist/esm/editor-commands/transforms/container-transforms.js +0 -441
  67. package/dist/esm/editor-commands/transforms/inline-node-transforms.js +0 -33
  68. package/dist/esm/editor-commands/transforms/layout/utils.js +0 -348
  69. package/dist/esm/editor-commands/transforms/layout-transforms.js +0 -72
  70. package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +0 -90
  71. package/dist/esm/editor-commands/transforms/list/transformTaskListToBlockNodes.js +0 -53
  72. package/dist/esm/editor-commands/transforms/list/transformToTaskList.js +0 -37
  73. package/dist/esm/editor-commands/transforms/list-transforms.js +0 -155
  74. package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +0 -72
  75. package/dist/esm/editor-commands/transforms/utils.js +0 -253
  76. package/dist/types/editor-commands/transforms/block-transforms.d.ts +0 -5
  77. package/dist/types/editor-commands/transforms/container-transforms.d.ts +0 -20
  78. package/dist/types/editor-commands/transforms/inline-node-transforms.d.ts +0 -6
  79. package/dist/types/editor-commands/transforms/layout/utils.d.ts +0 -5
  80. package/dist/types/editor-commands/transforms/layout-transforms.d.ts +0 -6
  81. package/dist/types/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +0 -3
  82. package/dist/types/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +0 -3
  83. package/dist/types/editor-commands/transforms/list/transformToTaskList.d.ts +0 -10
  84. package/dist/types/editor-commands/transforms/list-transforms.d.ts +0 -23
  85. package/dist/types/editor-commands/transforms/transformNodeToTargetType.d.ts +0 -14
  86. package/dist/types/editor-commands/transforms/utils.d.ts +0 -45
  87. package/dist/types-ts4.5/editor-commands/transforms/block-transforms.d.ts +0 -5
  88. package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +0 -20
  89. package/dist/types-ts4.5/editor-commands/transforms/inline-node-transforms.d.ts +0 -6
  90. package/dist/types-ts4.5/editor-commands/transforms/layout/utils.d.ts +0 -5
  91. package/dist/types-ts4.5/editor-commands/transforms/layout-transforms.d.ts +0 -6
  92. package/dist/types-ts4.5/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +0 -3
  93. package/dist/types-ts4.5/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +0 -3
  94. package/dist/types-ts4.5/editor-commands/transforms/list/transformToTaskList.d.ts +0 -10
  95. package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +0 -23
  96. package/dist/types-ts4.5/editor-commands/transforms/transformNodeToTargetType.d.ts +0 -14
  97. package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +0 -45
  98. /package/dist/cjs/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
  99. /package/dist/cjs/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
  100. /package/dist/cjs/editor-commands/{transforms/types.js → types.js} +0 -0
  101. /package/dist/es2019/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
  102. /package/dist/es2019/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
  103. /package/dist/es2019/editor-commands/{transforms/types.js → types.js} +0 -0
  104. /package/dist/esm/editor-commands/transform-node-utils/{flattenStep.js → steps/flattenStep.js} +0 -0
  105. /package/dist/esm/editor-commands/transform-node-utils/{unwrapStep.js → steps/unwrapStep.js} +0 -0
  106. /package/dist/esm/editor-commands/{transforms/types.js → types.js} +0 -0
@@ -1,441 +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 { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType, getMarksWithBreakout } from './utils';
6
- var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
7
- var validTransformedContent = [];
8
- // Headings are not valid inside headings so convert heading nodes to paragraphs
9
- sourceContent.forEach(function (node) {
10
- if (sourceNodeType === node.type) {
11
- validTransformedContent.push(validNodeType.createChecked(node.attrs, node.content, withMarks ? node.marks : undefined));
12
- } else {
13
- validTransformedContent.push(node);
14
- }
15
- });
16
- return Fragment.from(validTransformedContent);
17
- };
18
-
19
- /**
20
- * Transform selection to container type
21
- */
22
- export var transformToContainer = function transformToContainer(_ref) {
23
- var tr = _ref.tr,
24
- sourceNode = _ref.sourceNode,
25
- targetNodeType = _ref.targetNodeType,
26
- targetAttrs = _ref.targetAttrs;
27
- var selection = tr.selection;
28
- var schema = tr.doc.type.schema;
29
- var content = selection.content().content;
30
- var transformedContent = content;
31
- var marks = [];
32
- if (sourceNode.type === schema.nodes.codeBlock) {
33
- var paragraphNodes = convertCodeBlockContentToParagraphs(sourceNode, schema);
34
- transformedContent = Fragment.fromArray(paragraphNodes);
35
- marks = getMarksWithBreakout(sourceNode, targetNodeType);
36
- }
37
- if (targetNodeType === schema.nodes.blockquote) {
38
- transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
39
- }
40
-
41
- // Preserve marks that are allowed in the target node type
42
- // e.g. blocks (heading/ paragraph) with alignment need to remove alignment
43
- // as panel/ blockQuote/ expands does not support alignment
44
- if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
45
- transformedContent = filterMarksForTargetNodeType(transformedContent, targetNodeType);
46
- }
47
- var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent, marks);
48
- if (!newNode) {
49
- return null;
50
- }
51
- tr.replaceRangeWith(selection.from, selection.to, newNode);
52
- return tr;
53
- };
54
-
55
- /**
56
- * Transform container nodes (panel, expand, blockquote)
57
- */
58
- export var transformContainerNode = function transformContainerNode(_ref2) {
59
- var tr = _ref2.tr,
60
- sourceNode = _ref2.sourceNode,
61
- sourcePos = _ref2.sourcePos,
62
- targetNodeType = _ref2.targetNodeType,
63
- targetAttrs = _ref2.targetAttrs;
64
- if (sourcePos === null) {
65
- return null;
66
- }
67
-
68
- // Transform container to block type - unwrap and convert content
69
- if (isBlockNodeType(targetNodeType)) {
70
- // special case container to codeblock
71
- if (targetNodeType.name === 'codeBlock') {
72
- return transformBetweenContainerTypes({
73
- tr: tr,
74
- sourceNode: sourceNode,
75
- sourcePos: sourcePos,
76
- targetNodeType: targetNodeType,
77
- targetAttrs: targetAttrs
78
- });
79
- }
80
- return unwrapAndConvertToBlockType({
81
- tr: tr,
82
- sourceNode: sourceNode,
83
- sourcePos: sourcePos,
84
- targetNodeType: targetNodeType,
85
- targetAttrs: targetAttrs
86
- });
87
- }
88
-
89
- // Transform container to list type
90
- if (isListNodeType(targetNodeType)) {
91
- return unwrapAndConvertToList({
92
- tr: tr,
93
- sourceNode: sourceNode,
94
- sourcePos: sourcePos,
95
- targetNodeType: targetNodeType,
96
- targetAttrs: targetAttrs
97
- });
98
- }
99
-
100
- // Transform between container types
101
- if (isContainerNodeType(targetNodeType)) {
102
- return transformBetweenContainerTypes({
103
- tr: tr,
104
- sourceNode: sourceNode,
105
- sourcePos: sourcePos,
106
- targetNodeType: targetNodeType,
107
- targetAttrs: targetAttrs
108
- });
109
- }
110
- return null;
111
- };
112
-
113
- /**
114
- * Unwrap container node and convert content to block type
115
- */
116
- export var unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType(context) {
117
- var tr = context.tr,
118
- targetNodeType = context.targetNodeType,
119
- targetAttrs = context.targetAttrs,
120
- sourceNode = context.sourceNode,
121
- sourcePos = context.sourcePos;
122
- var selection = tr.selection;
123
- var schema = selection.$from.doc.type.schema;
124
- var _schema$nodes = schema.nodes,
125
- paragraph = _schema$nodes.paragraph,
126
- heading = _schema$nodes.heading,
127
- codeBlock = _schema$nodes.codeBlock,
128
- expand = _schema$nodes.expand;
129
- var rangeStart = sourcePos !== null ? sourcePos : selection.from;
130
- var sourceChildren = _toConsumableArray(sourceNode.children);
131
- var transformedContent = [];
132
-
133
- // If the container is expand, we need to extract the title and convert it to a paragraph
134
- // and add it to the beginning of the content
135
- if (sourceNode.type === expand) {
136
- var _sourceNode$attrs;
137
- var title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
138
- if (title) {
139
- var titleContent = schema.text(title);
140
- sourceChildren.unshift(paragraph.createChecked({}, titleContent));
141
- }
142
- }
143
-
144
- // if the container is a code block, convert text content to multiple paragraphs
145
- if (sourceNode.type === codeBlock) {
146
- sourceChildren = convertCodeBlockContentToParagraphs(sourceNode, schema);
147
- }
148
-
149
- // if target node is a paragraph, just do unwrap
150
- if (targetNodeType === paragraph) {
151
- transformedContent = sourceChildren;
152
- }
153
-
154
- // if target node is a headings, do unwrap and convert to heading
155
- if (targetNodeType === heading && targetAttrs) {
156
- var targetHeadingLevel = targetAttrs.level;
157
- sourceChildren.forEach(function (node, index) {
158
- if (node.isTextblock) {
159
- var headingNode = heading.create({
160
- level: targetHeadingLevel
161
- }, node.content);
162
- sourceChildren[index] = headingNode;
163
- }
164
- });
165
- transformedContent = sourceChildren;
166
- }
167
-
168
- // if target node is code block, do unwrap and convert to code block
169
- if (targetNodeType === codeBlock) {
170
- var codeBlockContent = sourceChildren.map(function (node) {
171
- return node.content.textBetween(0, node.content.size, '\n');
172
- }).join('\n');
173
- var marks = getMarksWithBreakout(sourceNode, targetNodeType);
174
- transformedContent = [codeBlock.createChecked({}, schema.text(codeBlockContent), marks)];
175
- }
176
- var slice = new Slice(Fragment.fromArray(transformedContent), 0, 0);
177
- tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
178
- return tr;
179
- };
180
-
181
- /**
182
- * Unwrap container node and convert content to list
183
- */
184
- export var unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
185
- var tr = _ref3.tr,
186
- sourceNode = _ref3.sourceNode,
187
- sourcePos = _ref3.sourcePos,
188
- targetNodeType = _ref3.targetNodeType,
189
- targetAttrs = _ref3.targetAttrs;
190
- var schema = tr.doc.type.schema;
191
- var _schema$nodes2 = schema.nodes,
192
- listItem = _schema$nodes2.listItem,
193
- paragraph = _schema$nodes2.paragraph,
194
- taskList = _schema$nodes2.taskList,
195
- taskItem = _schema$nodes2.taskItem,
196
- heading = _schema$nodes2.heading;
197
- var isTargetTaskList = targetNodeType === taskList;
198
- var createListItemFromInline = function createListItemFromInline(content) {
199
- if (!content) {
200
- return isTargetTaskList ? taskItem.create() : listItem.create(null, paragraph.create());
201
- } else {
202
- return isTargetTaskList ? taskItem.create(null, content) : listItem.create(null, paragraph.create(null, content));
203
- }
204
- };
205
- var getInlineContent = function getInlineContent(textblock) {
206
- var inlineContent = [];
207
- textblock.forEach(function (inline) {
208
- inlineContent.push(inline);
209
- });
210
- return inlineContent;
211
- };
212
- var resultContent = [];
213
- var currentListItems = [];
214
- var targetListItemType = isTargetTaskList ? taskItem : listItem;
215
- // Expand's title should become the first item of the list
216
- if (sourceNode.type.name === 'expand') {
217
- var _sourceNode$attrs2;
218
- var title = (_sourceNode$attrs2 = sourceNode.attrs) === null || _sourceNode$attrs2 === void 0 ? void 0 : _sourceNode$attrs2.title;
219
- if (title) {
220
- var titleContent = schema.text(title);
221
- currentListItems.push(createListItemFromInline(titleContent));
222
- }
223
- }
224
- var createListAndAddToContent = function createListAndAddToContent() {
225
- if (currentListItems.length) {
226
- var currentList = targetNodeType.create(targetAttrs || null, Fragment.from(currentListItems));
227
- currentListItems = [];
228
- resultContent.push(currentList);
229
- }
230
- };
231
- if (sourceNode.type.name === 'codeBlock') {
232
- var codeText = sourceNode.textContent;
233
- // check if code block only contains newline characters
234
- // eslint-disable-next-line require-unicode-regexp
235
- var isOnlyNewLines = function isOnlyNewLines(codeText) {
236
- return codeText.replace(/\n/g, '').trim() === '';
237
- };
238
- if (!codeText || isOnlyNewLines(codeText)) {
239
- // Empty code block - create an empty list item
240
- currentListItems.push(createListItemFromInline());
241
- }
242
- if (codeText) {
243
- var lines = codeText.split('\n');
244
- // Remove empty lines
245
- var nonEmptyLines = lines.filter(function (line) {
246
- return line.trim().length > 0;
247
- });
248
- nonEmptyLines.forEach(function (line) {
249
- var lineText = schema.text(line);
250
- currentListItems.push(createListItemFromInline(lineText));
251
- });
252
- }
253
- } else {
254
- sourceNode.forEach(function (child) {
255
- if (targetListItemType.validContent(Fragment.from(child))) {
256
- currentListItems.push(targetListItemType.create(null, child));
257
- } else if (heading === child.type || isTargetTaskList && paragraph === child.type) {
258
- var inline = Fragment.from(getInlineContent(child));
259
- currentListItems.push(createListItemFromInline(inline));
260
- } else {
261
- // Create list and add list first
262
- createListAndAddToContent();
263
- // Then add content that can't be converted into listItem
264
- resultContent.push(child);
265
- }
266
- });
267
- }
268
- if (!resultContent.length && !currentListItems.length) {
269
- return null;
270
- }
271
- createListAndAddToContent();
272
- return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, Fragment.from(resultContent));
273
- };
274
- export var transformBetweenContainerTypes = function transformBetweenContainerTypes(context) {
275
- var tr = context.tr,
276
- sourceNode = context.sourceNode,
277
- sourcePos = context.sourcePos,
278
- targetNodeType = context.targetNodeType,
279
- targetAttrs = context.targetAttrs;
280
-
281
- // Special handling for codeBlock target
282
- if (targetNodeType.name === 'codeBlock') {
283
- var _contentSplits = splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, tr.doc.type.schema);
284
- if (_contentSplits.length === 0) {
285
- var schema = tr.doc.type.schema;
286
- var marks = getMarksWithBreakout(sourceNode, targetNodeType);
287
- var codeBlock = schema.nodes.codeBlock.create(targetAttrs, null, marks);
288
- return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, codeBlock);
289
- }
290
- return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, _contentSplits);
291
- }
292
-
293
- // Get content validation for target container type
294
- var isContentSupported = getContentSupportChecker(targetNodeType);
295
-
296
- // Process content and collect splits
297
- var contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
298
- return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, contentSplits);
299
- };
300
-
301
- /**
302
- * Apply content splits to transaction - shared utility for replacing and inserting splits
303
- */
304
- var applySplitsToTransaction = function applySplitsToTransaction(tr, sourcePos, sourceNodeSize, contentSplits) {
305
- var insertPos = sourcePos;
306
- contentSplits.forEach(function (splitNode, index) {
307
- if (index === 0) {
308
- // Replace the original node with the first split
309
- tr.replaceWith(sourcePos, sourcePos + sourceNodeSize, splitNode);
310
- insertPos = sourcePos + splitNode.nodeSize;
311
- } else {
312
- // Insert additional splits after
313
- tr.insert(insertPos, splitNode);
314
- insertPos += splitNode.nodeSize;
315
- }
316
- });
317
- return tr;
318
- };
319
-
320
- /**
321
- * Split content for codeBlock transformation, creating codeBlocks for text content
322
- * and preserving unsupported blocks (like tables) separately
323
- */
324
- var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, schema) {
325
- var _sourceNode$attrs3;
326
- var splits = [];
327
- var children = sourceNode.content.content;
328
- var currentTextContent = [];
329
- var invalidContent = [];
330
- // Handle expand title - add as first text if source is expand with title
331
- if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
332
- currentTextContent.push(sourceNode.attrs.title);
333
- }
334
- var flushCurrentCodeBlock = function flushCurrentCodeBlock() {
335
- if (currentTextContent.length > 0) {
336
- var codeText = currentTextContent.join('\n');
337
- var marks = getMarksWithBreakout(sourceNode, targetNodeType);
338
- var codeBlockNode = targetNodeType.create(targetAttrs, schema.text(codeText), marks);
339
- splits.push(codeBlockNode);
340
- currentTextContent = [];
341
- }
342
- };
343
- var isCodeBlockCompatible = function isCodeBlockCompatible(node) {
344
- // Only text blocks (paragraph, heading) can be converted to codeBlock text
345
- return node.isTextblock || node.type.name === 'codeBlock';
346
- };
347
- children.forEach(function (childNode) {
348
- if (isCodeBlockCompatible(childNode)) {
349
- // Extract text content from compatible nodes
350
- if (childNode.type.name === 'codeBlock') {
351
- // If it's already a codeBlock, extract its text
352
- currentTextContent.push(childNode.textContent);
353
- } else if (childNode.isTextblock) {
354
- // Extract text from text blocks (paragraphs, headings, etc.)
355
- var text = getInlineNodeTextContent(Fragment.from(childNode)).inlineTextContent;
356
- if (text.trim()) {
357
- currentTextContent.push(text);
358
- }
359
- }
360
- } else if (isBlockNodeForExtraction(childNode)) {
361
- // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
362
- flushCurrentCodeBlock();
363
- splits.push(childNode);
364
- } else if (isListNodeType(childNode.type)) {
365
- var isTaskList = childNode.type.name === 'taskList';
366
- var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
367
- var listItems = findChildrenByType(childNode, listItemType);
368
- listItems.forEach(function (listItem) {
369
- var content = isTaskList ? Fragment.from(listItem.node) : listItem.node.content;
370
- var inlineContent = getInlineNodeTextContent(content);
371
- if (inlineContent.inlineTextContent.trim()) {
372
- currentTextContent.push(inlineContent.inlineTextContent);
373
- }
374
- if (inlineContent.invalidContent.length > 0) {
375
- invalidContent.push.apply(invalidContent, _toConsumableArray(inlineContent.invalidContent));
376
- }
377
- });
378
- } else {
379
- // Other unsupported content - try to extract text if possible
380
- var _text = childNode.textContent;
381
- if (_text && _text.trim()) {
382
- currentTextContent.push(_text);
383
- }
384
- }
385
- });
386
-
387
- // Flush any remaining text content as a codeBlock
388
- flushCurrentCodeBlock();
389
- return [].concat(splits, invalidContent);
390
- };
391
-
392
- /**
393
- * Split content around unsupported block nodes, creating separate containers
394
- * for content before and after each unsupported block
395
- */
396
- var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, schema) {
397
- var _sourceNode$attrs4;
398
- var splits = [];
399
- var children = sourceNode.content.content;
400
- var currentContainerContent = [];
401
-
402
- // Handle expand title - add as first paragraph if source is expand with title
403
- if (sourceNode.type.name === 'expand' && (_sourceNode$attrs4 = sourceNode.attrs) !== null && _sourceNode$attrs4 !== void 0 && _sourceNode$attrs4.title) {
404
- var titleParagraph = schema.nodes.paragraph.create({}, schema.text(sourceNode.attrs.title));
405
- currentContainerContent.push(titleParagraph);
406
- }
407
- var flushCurrentContainer = function flushCurrentContainer() {
408
- if (currentContainerContent.length > 0) {
409
- var marks = getMarksWithBreakout(sourceNode, targetNodeType);
410
- var containerNode = targetNodeType.create(targetAttrs, Fragment.fromArray(currentContainerContent), marks);
411
- splits.push(containerNode);
412
- currentContainerContent = [];
413
- }
414
- };
415
- children.forEach(function (childNode) {
416
- if (isContentSupported(childNode)) {
417
- // Supported content - add to current container
418
- currentContainerContent.push(childNode);
419
- } else if (childNode.type.name === targetNodeType.name) {
420
- // Same type of container merge contents
421
- childNode.content.forEach(function (child) {
422
- currentContainerContent.push(child);
423
- });
424
- } else if (childNode.isBlock) {
425
- // Unsupported block node - flush current container, add block, continue
426
- flushCurrentContainer();
427
- splits.push(childNode);
428
- } else {
429
- // Unsupported inline content - convert to paragraph and add to container
430
- var inlineContent = convertNodeToInlineContent(childNode, schema);
431
- if (inlineContent.length > 0) {
432
- var paragraph = schema.nodes.paragraph.create({}, Fragment.fromArray(inlineContent));
433
- currentContainerContent.push(paragraph);
434
- }
435
- }
436
- });
437
-
438
- // Flush any remaining container content
439
- flushCurrentContainer();
440
- return splits;
441
- };
@@ -1,33 +0,0 @@
1
- import { isListNodeType } from './utils';
2
- export var getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent) {
3
- var validTransformedContent = '';
4
- var invalidContent = [];
5
- if (sourceContent.content.length < 1) {
6
- return {
7
- inlineTextContent: '',
8
- invalidContent: invalidContent
9
- };
10
- }
11
- // Headings are not valid inside headings so convert heading nodes to paragraphs
12
- sourceContent.forEach(function (node) {
13
- if (['paragraph', 'heading', 'taskItem', 'codeBlock'].includes(node.type.name)) {
14
- node.content.forEach(function (inlineNode) {
15
- if (inlineNode.type.name === 'status') {
16
- validTransformedContent += inlineNode.attrs.text;
17
- } else {
18
- validTransformedContent += "".concat(inlineNode.textContent);
19
- }
20
- });
21
- } else if (!isListNodeType(node.type)) {
22
- invalidContent.push(node);
23
- }
24
- });
25
- return {
26
- inlineTextContent: validTransformedContent,
27
- invalidContent: invalidContent
28
- };
29
- };
30
- export var getInlineNodeTextNode = function getInlineNodeTextNode(sourceContent, schema) {
31
- var text = getInlineNodeTextContent(sourceContent).inlineTextContent;
32
- return schema.text(text);
33
- };