@atlaskit/editor-plugin-block-menu 1.0.11 → 1.0.12
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 +12 -0
- package/dist/cjs/editor-commands/transforms/container-transforms.js +8 -25
- package/dist/cjs/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/cjs/editor-commands/transforms/utils.js +34 -1
- package/dist/es2019/editor-commands/transforms/container-transforms.js +8 -23
- package/dist/es2019/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/es2019/editor-commands/transforms/utils.js +33 -0
- package/dist/esm/editor-commands/transforms/container-transforms.js +8 -25
- package/dist/esm/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/esm/editor-commands/transforms/utils.js +33 -0
- package/dist/types/editor-commands/transforms/utils.d.ts +11 -0
- package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 1.0.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`6e27819feadc7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6e27819feadc7) -
|
|
8
|
+
ED-29183: Fixed aligned p and heading not able to convert to list
|
|
9
|
+
- [`6a9265f5389db`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6a9265f5389db) -
|
|
10
|
+
Fix container transform with blockquote containing list
|
|
11
|
+
- [`24e0d952943aa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/24e0d952943aa) -
|
|
12
|
+
ED-29206: Fixed conversion from code block to panel, expand text formatting issue
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 1.0.11
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -20,19 +20,6 @@ var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeTy
|
|
|
20
20
|
});
|
|
21
21
|
return _model.Fragment.from(validTransformedContent);
|
|
22
22
|
};
|
|
23
|
-
var filterMarksForTargetNodeType = function filterMarksForTargetNodeType(content, targetNodeType) {
|
|
24
|
-
var withValidMarks = [];
|
|
25
|
-
content.forEach(function (node) {
|
|
26
|
-
if (node.marks.length > 0) {
|
|
27
|
-
var allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
28
|
-
var updatedNode = node.mark(allowedMarks);
|
|
29
|
-
withValidMarks.push(updatedNode);
|
|
30
|
-
} else {
|
|
31
|
-
withValidMarks.push(node);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return _model.Fragment.from(withValidMarks);
|
|
35
|
-
};
|
|
36
23
|
|
|
37
24
|
/**
|
|
38
25
|
* Transform selection to container type
|
|
@@ -47,7 +34,8 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
47
34
|
var content = selection.content().content;
|
|
48
35
|
var transformedContent = content;
|
|
49
36
|
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
50
|
-
|
|
37
|
+
var paragraphNodes = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
38
|
+
transformedContent = _model.Fragment.fromArray(paragraphNodes);
|
|
51
39
|
}
|
|
52
40
|
if (targetNodeType === schema.nodes.blockquote) {
|
|
53
41
|
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
|
|
@@ -57,7 +45,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
57
45
|
// e.g. blocks (heading/ paragraph) with alignment need to remove alignment
|
|
58
46
|
// as panel/ blockQuote/ expands does not support alignment
|
|
59
47
|
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
60
|
-
transformedContent = filterMarksForTargetNodeType(transformedContent, targetNodeType);
|
|
48
|
+
transformedContent = (0, _utils.filterMarksForTargetNodeType)(transformedContent, targetNodeType);
|
|
61
49
|
}
|
|
62
50
|
var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent);
|
|
63
51
|
if (!newNode) {
|
|
@@ -158,12 +146,7 @@ var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function
|
|
|
158
146
|
|
|
159
147
|
// if the container is a code block, convert text content to multiple paragraphs
|
|
160
148
|
if (sourceNode.type === codeBlock) {
|
|
161
|
-
|
|
162
|
-
var lines = codeText.split('\n');
|
|
163
|
-
var paragraphNodes = lines.map(function (line) {
|
|
164
|
-
return paragraph.create(null, line ? schema.text(line) : null);
|
|
165
|
-
});
|
|
166
|
-
sourceChildren = paragraphNodes;
|
|
149
|
+
sourceChildren = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
167
150
|
}
|
|
168
151
|
|
|
169
152
|
// if target node is a paragraph, just do unwrap
|
|
@@ -400,15 +383,15 @@ var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupported
|
|
|
400
383
|
if (isContentSupported(childNode)) {
|
|
401
384
|
// Supported content - add to current container
|
|
402
385
|
currentContainerContent.push(childNode);
|
|
403
|
-
} else if ((0, _utils.isBlockNodeForExtraction)(childNode)) {
|
|
404
|
-
// Unsupported block node - flush current container, add block, continue
|
|
405
|
-
flushCurrentContainer();
|
|
406
|
-
splits.push(childNode);
|
|
407
386
|
} else if (childNode.type.name === targetNodeType.name) {
|
|
408
387
|
// Same type of container merge contents
|
|
409
388
|
childNode.content.forEach(function (child) {
|
|
410
389
|
currentContainerContent.push(child);
|
|
411
390
|
});
|
|
391
|
+
} else if (childNode.isBlock) {
|
|
392
|
+
// Unsupported block node - flush current container, add block, continue
|
|
393
|
+
flushCurrentContainer();
|
|
394
|
+
splits.push(childNode);
|
|
412
395
|
} else {
|
|
413
396
|
// Unsupported inline content - convert to paragraph and add to container
|
|
414
397
|
var inlineContent = (0, _utils.convertNodeToInlineContent)(childNode, schema);
|
|
@@ -24,6 +24,7 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
24
24
|
var _tr$selection = tr.selection,
|
|
25
25
|
$from = _tr$selection.$from,
|
|
26
26
|
$to = _tr$selection.$to;
|
|
27
|
+
var schema = tr.doc.type.schema;
|
|
27
28
|
var range = $from.blockRange($to);
|
|
28
29
|
if (!range) {
|
|
29
30
|
return null;
|
|
@@ -36,6 +37,12 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
36
37
|
return (0, _transformToTaskList.transformToTaskList)(tr, range, targetNodeType, targetAttrs, nodes);
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// filter marks that are not allowed in the target node type
|
|
41
|
+
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
42
|
+
var allowedMarks = targetNodeType.allowedMarks(sourceNode.marks);
|
|
43
|
+
tr.setNodeMarkup(range.start, null, null, allowedMarks);
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
40
47
|
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
41
48
|
tr.setBlockType(range.start, range.end, nodes.paragraph);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isTaskList = exports.isListNodeType = exports.isListNode = exports.isLayoutNodeType = exports.isContainerNodeType = exports.isContainerNode = exports.isBulletOrOrderedList = exports.isBlockNodeType = exports.isBlockNodeForExtraction = exports.isBlockNode = exports.getTargetNodeInfo = exports.getSupportedListTypesSet = exports.getSupportedListTypes = exports.getContentSupportChecker = exports.convertNodeToInlineContent = void 0;
|
|
6
|
+
exports.isTaskList = exports.isListNodeType = exports.isListNode = exports.isLayoutNodeType = exports.isContainerNodeType = exports.isContainerNode = exports.isBulletOrOrderedList = exports.isBlockNodeType = exports.isBlockNodeForExtraction = exports.isBlockNode = exports.getTargetNodeInfo = exports.getSupportedListTypesSet = exports.getSupportedListTypes = exports.getContentSupportChecker = exports.filterMarksForTargetNodeType = exports.convertNodeToInlineContent = exports.convertCodeBlockContentToParagraphs = void 0;
|
|
7
7
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
8
|
var getTargetNodeInfo = exports.getTargetNodeInfo = function getTargetNodeInfo(targetType, nodes) {
|
|
9
9
|
switch (targetType) {
|
|
@@ -174,4 +174,37 @@ var convertNodeToInlineContent = exports.convertNodeToInlineContent = function c
|
|
|
174
174
|
return [schema.text(node.textContent)];
|
|
175
175
|
}
|
|
176
176
|
return inlineNodes;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Filter marks from content based on the target node type
|
|
181
|
+
* @param content The content fragment to filter
|
|
182
|
+
* @param targetNodeType The target node type to check against
|
|
183
|
+
* @returns A new fragment with marks filtered for the target node type
|
|
184
|
+
*/
|
|
185
|
+
var filterMarksForTargetNodeType = exports.filterMarksForTargetNodeType = function filterMarksForTargetNodeType(content, targetNodeType) {
|
|
186
|
+
var withValidMarks = [];
|
|
187
|
+
content.forEach(function (node) {
|
|
188
|
+
if (node.marks.length > 0) {
|
|
189
|
+
var allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
190
|
+
var updatedNode = node.mark(allowedMarks);
|
|
191
|
+
withValidMarks.push(updatedNode);
|
|
192
|
+
} else {
|
|
193
|
+
withValidMarks.push(node);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return _model.Fragment.from(withValidMarks);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** * Convert content from a code block node into multiple paragraph nodes
|
|
200
|
+
*/
|
|
201
|
+
var convertCodeBlockContentToParagraphs = exports.convertCodeBlockContentToParagraphs = function convertCodeBlockContentToParagraphs(codeBlockNode, schema) {
|
|
202
|
+
var paragraphNodes = [];
|
|
203
|
+
var codeText = codeBlockNode.textContent;
|
|
204
|
+
var lines = codeText.split('\n');
|
|
205
|
+
lines.forEach(function (line) {
|
|
206
|
+
var paragraphNode = schema.nodes.paragraph.create(null, line ? schema.text(line) : null);
|
|
207
|
+
paragraphNodes.push(paragraphNode);
|
|
208
|
+
});
|
|
209
|
+
return paragraphNodes;
|
|
177
210
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker } from './utils';
|
|
2
|
+
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
|
|
3
3
|
const convertInvalidNodeToValidNodeType = (sourceContent, sourceNodeType, validNodeType, withMarks) => {
|
|
4
4
|
const validTransformedContent = [];
|
|
5
5
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
@@ -12,19 +12,6 @@ const convertInvalidNodeToValidNodeType = (sourceContent, sourceNodeType, validN
|
|
|
12
12
|
});
|
|
13
13
|
return Fragment.from(validTransformedContent);
|
|
14
14
|
};
|
|
15
|
-
const filterMarksForTargetNodeType = (content, targetNodeType) => {
|
|
16
|
-
const withValidMarks = [];
|
|
17
|
-
content.forEach(node => {
|
|
18
|
-
if (node.marks.length > 0) {
|
|
19
|
-
const allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
20
|
-
const updatedNode = node.mark(allowedMarks);
|
|
21
|
-
withValidMarks.push(updatedNode);
|
|
22
|
-
} else {
|
|
23
|
-
withValidMarks.push(node);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return Fragment.from(withValidMarks);
|
|
27
|
-
};
|
|
28
15
|
|
|
29
16
|
/**
|
|
30
17
|
* Transform selection to container type
|
|
@@ -40,7 +27,8 @@ export const transformToContainer = ({
|
|
|
40
27
|
const content = selection.content().content;
|
|
41
28
|
let transformedContent = content;
|
|
42
29
|
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
43
|
-
|
|
30
|
+
const paragraphNodes = convertCodeBlockContentToParagraphs(sourceNode, schema);
|
|
31
|
+
transformedContent = Fragment.fromArray(paragraphNodes);
|
|
44
32
|
}
|
|
45
33
|
if (targetNodeType === schema.nodes.blockquote) {
|
|
46
34
|
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
|
|
@@ -157,10 +145,7 @@ export const unwrapAndConvertToBlockType = context => {
|
|
|
157
145
|
|
|
158
146
|
// if the container is a code block, convert text content to multiple paragraphs
|
|
159
147
|
if (sourceNode.type === codeBlock) {
|
|
160
|
-
|
|
161
|
-
const lines = codeText.split('\n');
|
|
162
|
-
const paragraphNodes = lines.map(line => paragraph.create(null, line ? schema.text(line) : null));
|
|
163
|
-
sourceChildren = paragraphNodes;
|
|
148
|
+
sourceChildren = convertCodeBlockContentToParagraphs(sourceNode, schema);
|
|
164
149
|
}
|
|
165
150
|
|
|
166
151
|
// if target node is a paragraph, just do unwrap
|
|
@@ -399,15 +384,15 @@ const splitContentAroundUnsupportedBlocks = (sourceNode, isContentSupported, tar
|
|
|
399
384
|
if (isContentSupported(childNode)) {
|
|
400
385
|
// Supported content - add to current container
|
|
401
386
|
currentContainerContent.push(childNode);
|
|
402
|
-
} else if (isBlockNodeForExtraction(childNode)) {
|
|
403
|
-
// Unsupported block node - flush current container, add block, continue
|
|
404
|
-
flushCurrentContainer();
|
|
405
|
-
splits.push(childNode);
|
|
406
387
|
} else if (childNode.type.name === targetNodeType.name) {
|
|
407
388
|
// Same type of container merge contents
|
|
408
389
|
childNode.content.forEach(child => {
|
|
409
390
|
currentContainerContent.push(child);
|
|
410
391
|
});
|
|
392
|
+
} else if (childNode.isBlock) {
|
|
393
|
+
// Unsupported block node - flush current container, add block, continue
|
|
394
|
+
flushCurrentContainer();
|
|
395
|
+
splits.push(childNode);
|
|
411
396
|
} else {
|
|
412
397
|
// Unsupported inline content - convert to paragraph and add to container
|
|
413
398
|
const inlineContent = convertNodeToInlineContent(childNode, schema);
|
|
@@ -20,6 +20,7 @@ export const transformBlockToList = context => {
|
|
|
20
20
|
$from,
|
|
21
21
|
$to
|
|
22
22
|
} = tr.selection;
|
|
23
|
+
const schema = tr.doc.type.schema;
|
|
23
24
|
const range = $from.blockRange($to);
|
|
24
25
|
if (!range) {
|
|
25
26
|
return null;
|
|
@@ -34,6 +35,12 @@ export const transformBlockToList = context => {
|
|
|
34
35
|
return transformToTaskList(tr, range, targetNodeType, targetAttrs, nodes);
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
// filter marks that are not allowed in the target node type
|
|
39
|
+
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
40
|
+
const allowedMarks = targetNodeType.allowedMarks(sourceNode.marks);
|
|
41
|
+
tr.setNodeMarkup(range.start, null, null, allowedMarks);
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
38
45
|
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
39
46
|
tr.setBlockType(range.start, range.end, nodes.paragraph);
|
|
@@ -168,4 +168,37 @@ export const convertNodeToInlineContent = (node, schema) => {
|
|
|
168
168
|
return [schema.text(node.textContent)];
|
|
169
169
|
}
|
|
170
170
|
return inlineNodes;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Filter marks from content based on the target node type
|
|
175
|
+
* @param content The content fragment to filter
|
|
176
|
+
* @param targetNodeType The target node type to check against
|
|
177
|
+
* @returns A new fragment with marks filtered for the target node type
|
|
178
|
+
*/
|
|
179
|
+
export const filterMarksForTargetNodeType = (content, targetNodeType) => {
|
|
180
|
+
const withValidMarks = [];
|
|
181
|
+
content.forEach(node => {
|
|
182
|
+
if (node.marks.length > 0) {
|
|
183
|
+
const allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
184
|
+
const updatedNode = node.mark(allowedMarks);
|
|
185
|
+
withValidMarks.push(updatedNode);
|
|
186
|
+
} else {
|
|
187
|
+
withValidMarks.push(node);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return Fragment.from(withValidMarks);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** * Convert content from a code block node into multiple paragraph nodes
|
|
194
|
+
*/
|
|
195
|
+
export const convertCodeBlockContentToParagraphs = (codeBlockNode, schema) => {
|
|
196
|
+
const paragraphNodes = [];
|
|
197
|
+
const codeText = codeBlockNode.textContent;
|
|
198
|
+
const lines = codeText.split('\n');
|
|
199
|
+
lines.forEach(line => {
|
|
200
|
+
const paragraphNode = schema.nodes.paragraph.create(null, line ? schema.text(line) : null);
|
|
201
|
+
paragraphNodes.push(paragraphNode);
|
|
202
|
+
});
|
|
203
|
+
return paragraphNodes;
|
|
171
204
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker } from './utils';
|
|
3
|
+
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
|
|
4
4
|
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
5
5
|
var validTransformedContent = [];
|
|
6
6
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
@@ -13,19 +13,6 @@ var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeTy
|
|
|
13
13
|
});
|
|
14
14
|
return Fragment.from(validTransformedContent);
|
|
15
15
|
};
|
|
16
|
-
var filterMarksForTargetNodeType = function filterMarksForTargetNodeType(content, targetNodeType) {
|
|
17
|
-
var withValidMarks = [];
|
|
18
|
-
content.forEach(function (node) {
|
|
19
|
-
if (node.marks.length > 0) {
|
|
20
|
-
var allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
21
|
-
var updatedNode = node.mark(allowedMarks);
|
|
22
|
-
withValidMarks.push(updatedNode);
|
|
23
|
-
} else {
|
|
24
|
-
withValidMarks.push(node);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return Fragment.from(withValidMarks);
|
|
28
|
-
};
|
|
29
16
|
|
|
30
17
|
/**
|
|
31
18
|
* Transform selection to container type
|
|
@@ -40,7 +27,8 @@ export var transformToContainer = function transformToContainer(_ref) {
|
|
|
40
27
|
var content = selection.content().content;
|
|
41
28
|
var transformedContent = content;
|
|
42
29
|
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
43
|
-
|
|
30
|
+
var paragraphNodes = convertCodeBlockContentToParagraphs(sourceNode, schema);
|
|
31
|
+
transformedContent = Fragment.fromArray(paragraphNodes);
|
|
44
32
|
}
|
|
45
33
|
if (targetNodeType === schema.nodes.blockquote) {
|
|
46
34
|
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
|
|
@@ -151,12 +139,7 @@ export var unwrapAndConvertToBlockType = function unwrapAndConvertToBlockType(co
|
|
|
151
139
|
|
|
152
140
|
// if the container is a code block, convert text content to multiple paragraphs
|
|
153
141
|
if (sourceNode.type === codeBlock) {
|
|
154
|
-
|
|
155
|
-
var lines = codeText.split('\n');
|
|
156
|
-
var paragraphNodes = lines.map(function (line) {
|
|
157
|
-
return paragraph.create(null, line ? schema.text(line) : null);
|
|
158
|
-
});
|
|
159
|
-
sourceChildren = paragraphNodes;
|
|
142
|
+
sourceChildren = convertCodeBlockContentToParagraphs(sourceNode, schema);
|
|
160
143
|
}
|
|
161
144
|
|
|
162
145
|
// if target node is a paragraph, just do unwrap
|
|
@@ -393,15 +376,15 @@ var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupported
|
|
|
393
376
|
if (isContentSupported(childNode)) {
|
|
394
377
|
// Supported content - add to current container
|
|
395
378
|
currentContainerContent.push(childNode);
|
|
396
|
-
} else if (isBlockNodeForExtraction(childNode)) {
|
|
397
|
-
// Unsupported block node - flush current container, add block, continue
|
|
398
|
-
flushCurrentContainer();
|
|
399
|
-
splits.push(childNode);
|
|
400
379
|
} else if (childNode.type.name === targetNodeType.name) {
|
|
401
380
|
// Same type of container merge contents
|
|
402
381
|
childNode.content.forEach(function (child) {
|
|
403
382
|
currentContainerContent.push(child);
|
|
404
383
|
});
|
|
384
|
+
} else if (childNode.isBlock) {
|
|
385
|
+
// Unsupported block node - flush current container, add block, continue
|
|
386
|
+
flushCurrentContainer();
|
|
387
|
+
splits.push(childNode);
|
|
405
388
|
} else {
|
|
406
389
|
// Unsupported inline content - convert to paragraph and add to container
|
|
407
390
|
var inlineContent = convertNodeToInlineContent(childNode, schema);
|
|
@@ -18,6 +18,7 @@ export var transformBlockToList = function transformBlockToList(context) {
|
|
|
18
18
|
var _tr$selection = tr.selection,
|
|
19
19
|
$from = _tr$selection.$from,
|
|
20
20
|
$to = _tr$selection.$to;
|
|
21
|
+
var schema = tr.doc.type.schema;
|
|
21
22
|
var range = $from.blockRange($to);
|
|
22
23
|
if (!range) {
|
|
23
24
|
return null;
|
|
@@ -30,6 +31,12 @@ export var transformBlockToList = function transformBlockToList(context) {
|
|
|
30
31
|
return transformToTaskList(tr, range, targetNodeType, targetAttrs, nodes);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
// filter marks that are not allowed in the target node type
|
|
35
|
+
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
36
|
+
var allowedMarks = targetNodeType.allowedMarks(sourceNode.marks);
|
|
37
|
+
tr.setNodeMarkup(range.start, null, null, allowedMarks);
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
34
41
|
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
35
42
|
tr.setBlockType(range.start, range.end, nodes.paragraph);
|
|
@@ -168,4 +168,37 @@ export var convertNodeToInlineContent = function convertNodeToInlineContent(node
|
|
|
168
168
|
return [schema.text(node.textContent)];
|
|
169
169
|
}
|
|
170
170
|
return inlineNodes;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Filter marks from content based on the target node type
|
|
175
|
+
* @param content The content fragment to filter
|
|
176
|
+
* @param targetNodeType The target node type to check against
|
|
177
|
+
* @returns A new fragment with marks filtered for the target node type
|
|
178
|
+
*/
|
|
179
|
+
export var filterMarksForTargetNodeType = function filterMarksForTargetNodeType(content, targetNodeType) {
|
|
180
|
+
var withValidMarks = [];
|
|
181
|
+
content.forEach(function (node) {
|
|
182
|
+
if (node.marks.length > 0) {
|
|
183
|
+
var allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
184
|
+
var updatedNode = node.mark(allowedMarks);
|
|
185
|
+
withValidMarks.push(updatedNode);
|
|
186
|
+
} else {
|
|
187
|
+
withValidMarks.push(node);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return Fragment.from(withValidMarks);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** * Convert content from a code block node into multiple paragraph nodes
|
|
194
|
+
*/
|
|
195
|
+
export var convertCodeBlockContentToParagraphs = function convertCodeBlockContentToParagraphs(codeBlockNode, schema) {
|
|
196
|
+
var paragraphNodes = [];
|
|
197
|
+
var codeText = codeBlockNode.textContent;
|
|
198
|
+
var lines = codeText.split('\n');
|
|
199
|
+
lines.forEach(function (line) {
|
|
200
|
+
var paragraphNode = schema.nodes.paragraph.create(null, line ? schema.text(line) : null);
|
|
201
|
+
paragraphNodes.push(paragraphNode);
|
|
202
|
+
});
|
|
203
|
+
return paragraphNodes;
|
|
171
204
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Node as PMNode, NodeType, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { FormatNodeTargetType } from './types';
|
|
3
4
|
export declare const getTargetNodeInfo: (targetType: FormatNodeTargetType, nodes: Record<string, NodeType>) => {
|
|
4
5
|
attrs?: Record<string, unknown>;
|
|
@@ -28,3 +29,13 @@ export declare const getContentSupportChecker: (targetNodeType: NodeType) => ((n
|
|
|
28
29
|
* Convert a node to inline content that can be placed in a paragraph
|
|
29
30
|
*/
|
|
30
31
|
export declare const convertNodeToInlineContent: (node: PMNode, schema: Schema) => PMNode[];
|
|
32
|
+
/**
|
|
33
|
+
* Filter marks from content based on the target node type
|
|
34
|
+
* @param content The content fragment to filter
|
|
35
|
+
* @param targetNodeType The target node type to check against
|
|
36
|
+
* @returns A new fragment with marks filtered for the target node type
|
|
37
|
+
*/
|
|
38
|
+
export declare const filterMarksForTargetNodeType: (content: Fragment, targetNodeType: NodeType) => Fragment;
|
|
39
|
+
/** * Convert content from a code block node into multiple paragraph nodes
|
|
40
|
+
*/
|
|
41
|
+
export declare const convertCodeBlockContentToParagraphs: (codeBlockNode: PMNode, schema: Schema) => PMNode[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Node as PMNode, NodeType, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { FormatNodeTargetType } from './types';
|
|
3
4
|
export declare const getTargetNodeInfo: (targetType: FormatNodeTargetType, nodes: Record<string, NodeType>) => {
|
|
4
5
|
attrs?: Record<string, unknown>;
|
|
@@ -28,3 +29,13 @@ export declare const getContentSupportChecker: (targetNodeType: NodeType) => ((n
|
|
|
28
29
|
* Convert a node to inline content that can be placed in a paragraph
|
|
29
30
|
*/
|
|
30
31
|
export declare const convertNodeToInlineContent: (node: PMNode, schema: Schema) => PMNode[];
|
|
32
|
+
/**
|
|
33
|
+
* Filter marks from content based on the target node type
|
|
34
|
+
* @param content The content fragment to filter
|
|
35
|
+
* @param targetNodeType The target node type to check against
|
|
36
|
+
* @returns A new fragment with marks filtered for the target node type
|
|
37
|
+
*/
|
|
38
|
+
export declare const filterMarksForTargetNodeType: (content: Fragment, targetNodeType: NodeType) => Fragment;
|
|
39
|
+
/** * Convert content from a code block node into multiple paragraph nodes
|
|
40
|
+
*/
|
|
41
|
+
export declare const convertCodeBlockContentToParagraphs: (codeBlockNode: PMNode, schema: Schema) => PMNode[];
|