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