@atlaskit/editor-plugin-block-menu 1.0.0 → 1.0.2
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 +18 -0
- package/dist/cjs/editor-commands/formatNode.js +6 -3
- package/dist/cjs/editor-commands/transforms/block-transforms.js +22 -10
- package/dist/cjs/editor-commands/transforms/container-transforms.js +40 -7
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +27 -0
- package/dist/cjs/editor-commands/transforms/list/transformBetweenListTypes.js +102 -0
- package/dist/cjs/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +54 -0
- package/dist/cjs/editor-commands/transforms/list/transformTaskListToBlockNodes.js +59 -0
- package/dist/cjs/editor-commands/transforms/list-transforms.js +66 -20
- package/dist/cjs/ui/block-menu-components.js +1 -2
- package/dist/cjs/ui/block-menu.compiled.css +1 -1
- package/dist/cjs/ui/block-menu.js +1 -1
- package/dist/es2019/editor-commands/formatNode.js +6 -3
- package/dist/es2019/editor-commands/transforms/block-transforms.js +29 -15
- package/dist/es2019/editor-commands/transforms/container-transforms.js +35 -2
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +21 -0
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +98 -0
- package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +42 -0
- package/dist/es2019/editor-commands/transforms/list/transformTaskListToBlockNodes.js +47 -0
- package/dist/es2019/editor-commands/transforms/list-transforms.js +66 -16
- package/dist/es2019/ui/block-menu-components.js +1 -2
- package/dist/es2019/ui/block-menu.compiled.css +1 -1
- package/dist/es2019/ui/block-menu.js +1 -1
- package/dist/esm/editor-commands/formatNode.js +6 -3
- package/dist/esm/editor-commands/transforms/block-transforms.js +23 -11
- package/dist/esm/editor-commands/transforms/container-transforms.js +39 -7
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +21 -0
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +95 -0
- package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +48 -0
- package/dist/esm/editor-commands/transforms/list/transformTaskListToBlockNodes.js +53 -0
- package/dist/esm/editor-commands/transforms/list-transforms.js +65 -19
- package/dist/esm/ui/block-menu-components.js +1 -2
- package/dist/esm/ui/block-menu.compiled.css +1 -1
- package/dist/esm/ui/block-menu.js +1 -1
- package/dist/types/editor-commands/transforms/container-transforms.d.ts +2 -2
- package/dist/types/editor-commands/transforms/inline-node-transforms.d.ts +3 -0
- package/dist/types/editor-commands/transforms/list/transformBetweenListTypes.d.ts +9 -0
- package/dist/types/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +3 -0
- package/dist/types/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +3 -0
- package/dist/types/editor-commands/transforms/list-transforms.d.ts +5 -6
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +2 -2
- package/dist/types-ts4.5/editor-commands/transforms/inline-node-transforms.d.ts +3 -0
- package/dist/types-ts4.5/editor-commands/transforms/list/transformBetweenListTypes.d.ts +9 -0
- package/dist/types-ts4.5/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.d.ts +3 -0
- package/dist/types-ts4.5/editor-commands/transforms/list/transformTaskListToBlockNodes.d.ts +3 -0
- package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +5 -6
- package/package.json +3 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`32434f817d714`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/32434f817d714) -
|
|
8
|
+
ED-29126: Convert list to block nodes
|
|
9
|
+
- [`255837cfba315`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/255837cfba315) -
|
|
10
|
+
Internal changes to how border radius is applied.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 1.0.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`ecae39119dc4b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ecae39119dc4b) -
|
|
18
|
+
[ux] ED-28558 Wrap block nodes inside container nodes
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 1.0.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -27,19 +27,22 @@ var formatNode = exports.formatNode = function formatNode(targetType) {
|
|
|
27
27
|
nodePos = selectedNode.pos;
|
|
28
28
|
} else {
|
|
29
29
|
// Try to find parent node (including list parents)
|
|
30
|
-
var parentNode = (0, _utils.findParentNodeOfType)([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.layoutSection])(selection);
|
|
30
|
+
var parentNode = (0, _utils.findParentNodeOfType)([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
|
|
31
31
|
if (parentNode) {
|
|
32
32
|
nodeToFormat = parentNode.node;
|
|
33
33
|
nodePos = parentNode.pos;
|
|
34
|
-
|
|
34
|
+
var paragraphOrHeadingNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading])(selection);
|
|
35
35
|
// Special case: if we found a listItem, check if we need the parent list instead
|
|
36
|
-
if (parentNode.node.type === nodes.listItem) {
|
|
36
|
+
if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
|
|
37
37
|
var listParent = (0, _utils.findParentNodeOfType)([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
|
|
38
38
|
if (listParent) {
|
|
39
39
|
// For list transformations, we want the list parent, not the listItem
|
|
40
40
|
nodeToFormat = listParent.node;
|
|
41
41
|
nodePos = listParent.pos;
|
|
42
42
|
}
|
|
43
|
+
} else if (paragraphOrHeadingNode) {
|
|
44
|
+
nodeToFormat = paragraphOrHeadingNode.node;
|
|
45
|
+
nodePos = paragraphOrHeadingNode.pos;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -5,33 +5,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformBlockNode = void 0;
|
|
7
7
|
var _containerTransforms = require("./container-transforms");
|
|
8
|
+
var _inlineNodeTransforms = require("./inline-node-transforms");
|
|
8
9
|
var _listTransforms = require("./list-transforms");
|
|
9
10
|
var _utils = require("./utils");
|
|
10
11
|
/**
|
|
11
12
|
* Transform block nodes (paragraph, heading, codeblock)
|
|
12
13
|
*/
|
|
13
14
|
var transformBlockNode = exports.transformBlockNode = function transformBlockNode(context) {
|
|
14
|
-
var
|
|
15
|
-
targetNodeType = context.targetNodeType,
|
|
16
|
-
targetAttrs = context.targetAttrs;
|
|
17
|
-
var selection = tr.selection;
|
|
18
|
-
var $from = selection.$from,
|
|
19
|
-
$to = selection.$to;
|
|
15
|
+
var targetNodeType = context.targetNodeType;
|
|
20
16
|
|
|
21
17
|
// Handle transformation to list types
|
|
22
18
|
if ((0, _utils.isListNodeType)(targetNodeType)) {
|
|
23
|
-
return (0, _listTransforms.
|
|
19
|
+
return (0, _listTransforms.transformBlockToList)(context);
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
// Handle transformation to container types (panel, expand, blockquote)
|
|
27
23
|
if ((0, _utils.isContainerNodeType)(targetNodeType)) {
|
|
28
|
-
return (0, _containerTransforms.transformToContainer)();
|
|
24
|
+
return (0, _containerTransforms.transformToContainer)(context);
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
// Handle block type transformation (paragraph, heading, codeblock)
|
|
32
28
|
if ((0, _utils.isBlockNodeType)(targetNodeType)) {
|
|
33
|
-
|
|
34
|
-
return tr;
|
|
29
|
+
return transformToBlockNode(context);
|
|
35
30
|
}
|
|
36
31
|
return null;
|
|
32
|
+
};
|
|
33
|
+
var transformToBlockNode = function transformToBlockNode(context) {
|
|
34
|
+
var tr = context.tr,
|
|
35
|
+
targetNodeType = context.targetNodeType,
|
|
36
|
+
targetAttrs = context.targetAttrs;
|
|
37
|
+
var selection = tr.selection,
|
|
38
|
+
doc = tr.doc;
|
|
39
|
+
var $from = selection.$from,
|
|
40
|
+
$to = selection.$to;
|
|
41
|
+
var schema = doc.type.schema;
|
|
42
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
43
|
+
var textContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(selection.content().content, tr);
|
|
44
|
+
var node = schema.nodes.codeBlock.createChecked(undefined, textContent);
|
|
45
|
+
return tr.replaceRangeWith(selection.from, selection.to, node);
|
|
46
|
+
}
|
|
47
|
+
tr.setBlockType($from.pos, $to.pos, targetNodeType, targetAttrs);
|
|
48
|
+
return tr;
|
|
37
49
|
};
|
|
@@ -4,22 +4,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.unwrapAndConvertToList = exports.unwrapAndConvertToBlockType = exports.transformToContainer = exports.transformContainerNode = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
7
8
|
var _utils = require("./utils");
|
|
9
|
+
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
10
|
+
var validTransformedContent = [];
|
|
11
|
+
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
12
|
+
sourceContent.forEach(function (node) {
|
|
13
|
+
if (sourceNodeType === node.type) {
|
|
14
|
+
validTransformedContent.push(validNodeType.createChecked(node.attrs, node.content, withMarks ? node.marks : undefined));
|
|
15
|
+
} else {
|
|
16
|
+
validTransformedContent.push(node);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return _model.Fragment.from(validTransformedContent);
|
|
20
|
+
};
|
|
21
|
+
|
|
8
22
|
/**
|
|
9
23
|
* Transform selection to container type
|
|
10
24
|
*/
|
|
11
|
-
var transformToContainer = exports.transformToContainer = function transformToContainer() {
|
|
12
|
-
|
|
25
|
+
var transformToContainer = exports.transformToContainer = function transformToContainer(_ref) {
|
|
26
|
+
var tr = _ref.tr,
|
|
27
|
+
sourceNode = _ref.sourceNode,
|
|
28
|
+
targetNodeType = _ref.targetNodeType,
|
|
29
|
+
targetAttrs = _ref.targetAttrs;
|
|
30
|
+
var selection = tr.selection;
|
|
31
|
+
var schema = tr.doc.type.schema;
|
|
32
|
+
var content = selection.content().content;
|
|
33
|
+
var transformedContent = content;
|
|
34
|
+
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
35
|
+
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.codeBlock, schema.nodes.paragraph);
|
|
36
|
+
}
|
|
37
|
+
if (targetNodeType === schema.nodes.blockquote) {
|
|
38
|
+
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
|
|
39
|
+
}
|
|
40
|
+
var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent);
|
|
41
|
+
if (!newNode) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
tr.replaceRangeWith(selection.from, selection.to, newNode);
|
|
45
|
+
return tr;
|
|
13
46
|
};
|
|
14
47
|
|
|
15
48
|
/**
|
|
16
49
|
* Transform container nodes (panel, expand, blockquote)
|
|
17
50
|
*/
|
|
18
|
-
var transformContainerNode = exports.transformContainerNode = function transformContainerNode(
|
|
19
|
-
var tr =
|
|
20
|
-
sourcePos =
|
|
21
|
-
targetNodeType =
|
|
22
|
-
targetAttrs =
|
|
51
|
+
var transformContainerNode = exports.transformContainerNode = function transformContainerNode(_ref2) {
|
|
52
|
+
var tr = _ref2.tr,
|
|
53
|
+
sourcePos = _ref2.sourcePos,
|
|
54
|
+
targetNodeType = _ref2.targetNodeType,
|
|
55
|
+
targetAttrs = _ref2.targetAttrs;
|
|
23
56
|
if (sourcePos === null) {
|
|
24
57
|
return null;
|
|
25
58
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getInlineNodeTextContent = void 0;
|
|
7
|
+
var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent, tr) {
|
|
8
|
+
var validTransformedContent = '';
|
|
9
|
+
var schema = tr.doc.type.schema;
|
|
10
|
+
if (sourceContent.content.length > 1) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
14
|
+
sourceContent.forEach(function (node) {
|
|
15
|
+
if (['paragraph', 'heading'].includes(node.type.name)) {
|
|
16
|
+
node.content.forEach(function (inlineNode) {
|
|
17
|
+
if (inlineNode.type.name === 'status') {
|
|
18
|
+
validTransformedContent += inlineNode.attrs.text;
|
|
19
|
+
} else {
|
|
20
|
+
validTransformedContent += "".concat(inlineNode.textContent);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
validTransformedContent;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return schema.text(validTransformedContent);
|
|
27
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.transformListStructure = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
/**
|
|
10
|
+
* Extract all inline content from a node
|
|
11
|
+
*/
|
|
12
|
+
var extractInlineContent = function extractInlineContent(node) {
|
|
13
|
+
var inlineContent = [];
|
|
14
|
+
for (var i = 0; i < node.childCount; i++) {
|
|
15
|
+
inlineContent.push(node.child(i));
|
|
16
|
+
}
|
|
17
|
+
return inlineContent;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Transform list structure
|
|
22
|
+
*/
|
|
23
|
+
var transformListStructure = exports.transformListStructure = function transformListStructure(tr, listNode, targetNodeType, nodes) {
|
|
24
|
+
try {
|
|
25
|
+
var sourceList = listNode.node,
|
|
26
|
+
listPos = listNode.pos;
|
|
27
|
+
var bulletList = nodes.bulletList,
|
|
28
|
+
orderedList = nodes.orderedList,
|
|
29
|
+
taskList = nodes.taskList,
|
|
30
|
+
listItem = nodes.listItem,
|
|
31
|
+
taskItem = nodes.taskItem,
|
|
32
|
+
paragraph = nodes.paragraph;
|
|
33
|
+
var isSourceBulletOrOrdered = sourceList.type === bulletList || sourceList.type === orderedList;
|
|
34
|
+
var isTargetTask = targetNodeType === taskList;
|
|
35
|
+
var isSourceTask = sourceList.type === taskList;
|
|
36
|
+
var newListItems = [];
|
|
37
|
+
var listStart = listPos;
|
|
38
|
+
var listEnd = listPos + sourceList.nodeSize;
|
|
39
|
+
|
|
40
|
+
// Use nodesBetween to efficiently traverse the list structure
|
|
41
|
+
tr.doc.nodesBetween(listStart, listEnd, function (node, pos, parent) {
|
|
42
|
+
// Only process direct children of the list (depth 1)
|
|
43
|
+
if (parent !== sourceList) {
|
|
44
|
+
return true; // Continue traversal
|
|
45
|
+
}
|
|
46
|
+
if (isSourceBulletOrOrdered && isTargetTask) {
|
|
47
|
+
// Converting from bullet/ordered list to task list
|
|
48
|
+
// Extract inline content from all children within listItem
|
|
49
|
+
if (node.type === listItem) {
|
|
50
|
+
var inlineContent = [];
|
|
51
|
+
|
|
52
|
+
// Extract all inline content from all child nodes
|
|
53
|
+
for (var i = 0; i < node.childCount; i++) {
|
|
54
|
+
var child = node.child(i);
|
|
55
|
+
if (child.type === paragraph) {
|
|
56
|
+
// Extract inline content from paragraphs
|
|
57
|
+
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(extractInlineContent(child)));
|
|
58
|
+
} else if (child.isBlock) {
|
|
59
|
+
// For other block content types eg. codeBlock, extract their text content and create text nodes
|
|
60
|
+
var textContent = child.textContent;
|
|
61
|
+
if (textContent) {
|
|
62
|
+
var textNode = tr.doc.type.schema.text(textContent);
|
|
63
|
+
inlineContent.push(textNode);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// Already inline content, add directly
|
|
67
|
+
inlineContent.push(child);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (inlineContent.length > 0) {
|
|
71
|
+
var newItem = taskItem.create(null, inlineContent);
|
|
72
|
+
newListItems.push(newItem);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else if (isSourceTask && !isTargetTask) {
|
|
76
|
+
// Converting from task list to bullet/ordered list
|
|
77
|
+
// Structure: taskItem > inline content -> listItem > paragraph > inline content
|
|
78
|
+
if (node.type === taskItem) {
|
|
79
|
+
var _inlineContent = extractInlineContent(node);
|
|
80
|
+
if (_inlineContent.length > 0) {
|
|
81
|
+
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
82
|
+
var newListItem = listItem.create(null, paragraphNode);
|
|
83
|
+
newListItems.push(newListItem);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false; // Don't traverse into children of list items
|
|
88
|
+
});
|
|
89
|
+
if (newListItems.length === 0) {
|
|
90
|
+
return tr;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Create new list with transformed items
|
|
94
|
+
var newList = targetNodeType.create(null, newListItems);
|
|
95
|
+
|
|
96
|
+
// Replace the entire list
|
|
97
|
+
tr.replaceWith(listStart, listEnd, newList);
|
|
98
|
+
return tr;
|
|
99
|
+
} catch (_unused) {
|
|
100
|
+
return tr;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformOrderedUnorderedListToBlockNodes = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var transformOrderedUnorderedListToBlockNodes = exports.transformOrderedUnorderedListToBlockNodes = function transformOrderedUnorderedListToBlockNodes(context) {
|
|
10
|
+
var tr = context.tr,
|
|
11
|
+
targetNodeType = context.targetNodeType,
|
|
12
|
+
targetAttrs = context.targetAttrs,
|
|
13
|
+
sourceNode = context.sourceNode,
|
|
14
|
+
sourcePos = context.sourcePos;
|
|
15
|
+
var selection = tr.selection;
|
|
16
|
+
var schema = selection.$from.doc.type.schema;
|
|
17
|
+
// find all paragraph nodes inside the list node
|
|
18
|
+
var paragraphs = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.paragraph);
|
|
19
|
+
var paragraphNodes = paragraphs.map(function (paragraph) {
|
|
20
|
+
return paragraph.node;
|
|
21
|
+
});
|
|
22
|
+
var targetNodes = paragraphNodes;
|
|
23
|
+
|
|
24
|
+
// Convert paragraphs to headings if target is heading
|
|
25
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
26
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
27
|
+
targetNodes = paragraphNodes.map(function (paragraphNode) {
|
|
28
|
+
return schema.nodes.heading.createChecked({
|
|
29
|
+
level: targetHeadingLevel
|
|
30
|
+
}, paragraphNode.content);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Convert paragraphs to code block if target is code block
|
|
35
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
36
|
+
// convert the paragraphNodes to one code block
|
|
37
|
+
var listItemsResult = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.listItem);
|
|
38
|
+
var listItems = listItemsResult.map(function (item) {
|
|
39
|
+
return item.node;
|
|
40
|
+
});
|
|
41
|
+
var listItemFragments = listItems.map(function (listItem) {
|
|
42
|
+
return listItem.content;
|
|
43
|
+
});
|
|
44
|
+
var codeBlockContent = listItemFragments.map(function (fragment) {
|
|
45
|
+
return fragment.textBetween(0, fragment.size, '\n');
|
|
46
|
+
}).join('\n');
|
|
47
|
+
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
48
|
+
}
|
|
49
|
+
var fragment = _model.Fragment.fromArray(targetNodes);
|
|
50
|
+
var slice = new _model.Slice(fragment, 0, 0);
|
|
51
|
+
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
52
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
53
|
+
return tr;
|
|
54
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformTaskListToBlockNodes = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var transformTaskListToBlockNodes = exports.transformTaskListToBlockNodes = function transformTaskListToBlockNodes(context) {
|
|
10
|
+
var tr = context.tr,
|
|
11
|
+
targetNodeType = context.targetNodeType,
|
|
12
|
+
targetAttrs = context.targetAttrs,
|
|
13
|
+
sourceNode = context.sourceNode,
|
|
14
|
+
sourcePos = context.sourcePos;
|
|
15
|
+
var selection = tr.selection;
|
|
16
|
+
var schema = selection.$from.doc.type.schema;
|
|
17
|
+
var taskItemsResult = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.taskItem);
|
|
18
|
+
var taskItems = taskItemsResult.map(function (item) {
|
|
19
|
+
return item.node;
|
|
20
|
+
});
|
|
21
|
+
var taskItemFragments = taskItems.map(function (taskItem) {
|
|
22
|
+
return taskItem.content;
|
|
23
|
+
});
|
|
24
|
+
var targetNodes = [];
|
|
25
|
+
|
|
26
|
+
// Convert fragments to headings if target is heading
|
|
27
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
28
|
+
// convert the fragments to headings
|
|
29
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
30
|
+
targetNodes = taskItemFragments.map(function (fragment) {
|
|
31
|
+
return schema.nodes.heading.createChecked({
|
|
32
|
+
level: targetHeadingLevel
|
|
33
|
+
}, fragment.content);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Convert fragments to paragraphs if target is paragraphs
|
|
38
|
+
if (targetNodeType === schema.nodes.paragraph) {
|
|
39
|
+
// convert the fragments to paragraphs
|
|
40
|
+
targetNodes = taskItemFragments.map(function (fragment) {
|
|
41
|
+
return schema.nodes.paragraph.createChecked({}, fragment.content);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Convert fragments to code block if target is code block
|
|
46
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
47
|
+
// convert the fragments to one code block
|
|
48
|
+
var codeBlockContent = taskItemFragments.map(function (fragment) {
|
|
49
|
+
return fragment.textBetween(0, fragment.size, '\n');
|
|
50
|
+
}).join('\n');
|
|
51
|
+
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Replace the task list node with the new content in the transaction
|
|
55
|
+
var slice = new _model.Slice(_model.Fragment.fromArray(targetNodes), 0, 0);
|
|
56
|
+
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
57
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
58
|
+
return tr;
|
|
59
|
+
};
|
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.transformListToBlockNodes = exports.transformListNode = exports.transformBlockToList = exports.transformBetweenListTypes = exports.liftListToBlockType = void 0;
|
|
7
7
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
8
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var _transformBetweenListTypes = require("./list/transformBetweenListTypes");
|
|
10
|
+
var _transformOrderedUnorderedListToBlockNodes = require("./list/transformOrderedUnorderedListToBlockNodes");
|
|
11
|
+
var _transformTaskListToBlockNodes = require("./list/transformTaskListToBlockNodes");
|
|
9
12
|
var _utils2 = require("./utils");
|
|
10
13
|
/**
|
|
11
14
|
* Transform selection to list type
|
|
12
15
|
*/
|
|
13
|
-
var
|
|
14
|
-
var tr =
|
|
15
|
-
targetNodeType =
|
|
16
|
-
targetAttrs =
|
|
17
|
-
// Wrap selection in list of target type
|
|
16
|
+
var transformBlockToList = exports.transformBlockToList = function transformBlockToList(context) {
|
|
17
|
+
var tr = context.tr,
|
|
18
|
+
targetNodeType = context.targetNodeType,
|
|
19
|
+
targetAttrs = context.targetAttrs;
|
|
18
20
|
var _tr$selection = tr.selection,
|
|
19
21
|
$from = _tr$selection.$from,
|
|
20
22
|
$to = _tr$selection.$to;
|
|
@@ -22,16 +24,45 @@ var transformToList = exports.transformToList = function transformToList(_ref) {
|
|
|
22
24
|
if (!range) {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
27
|
+
var nodes = tr.doc.type.schema.nodes;
|
|
28
|
+
var isTargetTask = targetNodeType === nodes.taskList;
|
|
29
|
+
|
|
30
|
+
// Handle task lists differently due to their structure
|
|
31
|
+
// TODO: ED-29152 - Implement task list transformation
|
|
32
|
+
if (isTargetTask) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
25
35
|
|
|
26
|
-
//
|
|
27
|
-
var
|
|
36
|
+
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
37
|
+
var sourceNode = tr.doc.nodeAt(range.start);
|
|
38
|
+
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
39
|
+
tr.setBlockType(range.start, range.end, nodes.paragraph);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Get the current range (updated if we converted from heading)
|
|
43
|
+
var currentRange = tr.selection.$from.blockRange(tr.selection.$to) || range;
|
|
44
|
+
|
|
45
|
+
// Wrap in the target list type
|
|
46
|
+
var wrapping = (0, _transform.findWrapping)(currentRange, targetNodeType, targetAttrs);
|
|
28
47
|
if (!wrapping) {
|
|
29
48
|
return null;
|
|
30
49
|
}
|
|
31
|
-
tr.wrap(
|
|
50
|
+
tr.wrap(currentRange, wrapping);
|
|
32
51
|
return tr;
|
|
33
52
|
};
|
|
34
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Transform list to block nodes
|
|
56
|
+
*/
|
|
57
|
+
var transformListToBlockNodes = exports.transformListToBlockNodes = function transformListToBlockNodes(context) {
|
|
58
|
+
var sourceNode = context.sourceNode;
|
|
59
|
+
if (sourceNode.type.name === 'taskList') {
|
|
60
|
+
return (0, _transformTaskListToBlockNodes.transformTaskListToBlockNodes)(context);
|
|
61
|
+
} else {
|
|
62
|
+
return (0, _transformOrderedUnorderedListToBlockNodes.transformOrderedUnorderedListToBlockNodes)(context);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
35
66
|
/**
|
|
36
67
|
* Transform list nodes
|
|
37
68
|
*/
|
|
@@ -40,7 +71,7 @@ var transformListNode = exports.transformListNode = function transformListNode(c
|
|
|
40
71
|
// Transform list to block type
|
|
41
72
|
if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
|
|
42
73
|
// Lift list items out of the list and convert to target block type
|
|
43
|
-
return
|
|
74
|
+
return transformListToBlockNodes(context);
|
|
44
75
|
}
|
|
45
76
|
|
|
46
77
|
// Transform list to container type
|
|
@@ -67,22 +98,37 @@ var liftListToBlockType = exports.liftListToBlockType = function liftListToBlock
|
|
|
67
98
|
/**
|
|
68
99
|
* Transform between different list types
|
|
69
100
|
*/
|
|
70
|
-
var transformBetweenListTypes = exports.transformBetweenListTypes = function transformBetweenListTypes(
|
|
71
|
-
var tr =
|
|
72
|
-
targetNodeType =
|
|
73
|
-
var
|
|
101
|
+
var transformBetweenListTypes = exports.transformBetweenListTypes = function transformBetweenListTypes(_ref) {
|
|
102
|
+
var tr = _ref.tr,
|
|
103
|
+
targetNodeType = _ref.targetNodeType;
|
|
104
|
+
var _tr = tr,
|
|
105
|
+
selection = _tr.selection;
|
|
74
106
|
var nodes = tr.doc.type.schema.nodes;
|
|
75
107
|
|
|
76
|
-
// Find the list node
|
|
77
|
-
var
|
|
108
|
+
// Find the list node - support bullet lists, ordered lists, and task lists
|
|
109
|
+
var supportedListTypes = [nodes.bulletList, nodes.orderedList, nodes.taskList].filter(Boolean); // Filter out undefined nodes in case some schemas don't have all types
|
|
110
|
+
|
|
111
|
+
var listNode = (0, _utils.findParentNodeOfType)(supportedListTypes)(selection);
|
|
78
112
|
if (!listNode) {
|
|
79
113
|
return null;
|
|
80
114
|
}
|
|
115
|
+
var sourceListType = listNode.node.type;
|
|
116
|
+
var isSourceBulletOrOrdered = sourceListType === nodes.bulletList || sourceListType === nodes.orderedList;
|
|
117
|
+
var isTargetTask = targetNodeType === nodes.taskList;
|
|
118
|
+
var isSourceTask = sourceListType === nodes.taskList;
|
|
119
|
+
var isTargetBulletOrOrdered = targetNodeType === nodes.bulletList || targetNodeType === nodes.orderedList;
|
|
120
|
+
|
|
121
|
+
// Check if we need structure transformation
|
|
122
|
+
var needsStructureTransform = isSourceBulletOrOrdered && isTargetTask || isSourceTask && isTargetBulletOrOrdered;
|
|
81
123
|
try {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
124
|
+
if (!needsStructureTransform) {
|
|
125
|
+
// Simple type change for same structure lists (bullet <-> ordered)
|
|
126
|
+
tr.setNodeMarkup(listNode.pos, targetNodeType);
|
|
127
|
+
} else {
|
|
128
|
+
tr = (0, _transformBetweenListTypes.transformListStructure)(tr, listNode, targetNodeType, nodes);
|
|
129
|
+
}
|
|
130
|
+
} catch (_unused) {
|
|
86
131
|
return null;
|
|
87
132
|
}
|
|
133
|
+
return tr;
|
|
88
134
|
};
|
|
@@ -11,7 +11,6 @@ var _blockMenu = require("@atlaskit/editor-common/block-menu");
|
|
|
11
11
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
12
12
|
var _changes = _interopRequireDefault(require("@atlaskit/icon/core/changes"));
|
|
13
13
|
var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
|
|
14
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
14
|
var _copyBlock = _interopRequireDefault(require("./copy-block"));
|
|
16
15
|
var _copyLink = require("./copy-link");
|
|
17
16
|
var _deleteButton = require("./delete-button");
|
|
@@ -98,7 +97,7 @@ var getFormatMenuComponents = function getFormatMenuComponents() {
|
|
|
98
97
|
var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(_ref4) {
|
|
99
98
|
var api = _ref4.api,
|
|
100
99
|
config = _ref4.config;
|
|
101
|
-
return [].concat((0, _toConsumableArray2.default)(
|
|
100
|
+
return [].concat((0, _toConsumableArray2.default)(getFormatMenuComponents()), [{
|
|
102
101
|
type: 'block-menu-section',
|
|
103
102
|
key: _blockMenu.COPY_MENU_SECTION.key,
|
|
104
103
|
rank: _blockMenu.BLOCK_MENU_SECTION_RANK[_blockMenu.COPY_MENU_SECTION.key],
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
.
|
|
2
|
+
._2rko12b0{border-radius:var(--ds-radius-small,4px)}._16qs1cd0{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #091e4226,0 0 1px #091e424f)}
|
|
3
3
|
._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
|
|
@@ -21,7 +21,7 @@ var _compiled = require("@atlaskit/primitives/compiled");
|
|
|
21
21
|
var _blockMenuRenderer = require("./block-menu-renderer");
|
|
22
22
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
23
23
|
var styles = {
|
|
24
|
-
base: "
|
|
24
|
+
base: "_2rko12b0 _bfhk1bhr _16qs1cd0"
|
|
25
25
|
};
|
|
26
26
|
var DEFAULT_MENU_WIDTH = 230;
|
|
27
27
|
var DRAG_HANDLE_OFFSET_PADDING = 5;
|
|
@@ -26,19 +26,22 @@ export const formatNode = targetType => {
|
|
|
26
26
|
nodePos = selectedNode.pos;
|
|
27
27
|
} else {
|
|
28
28
|
// Try to find parent node (including list parents)
|
|
29
|
-
const parentNode = findParentNodeOfType([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.layoutSection])(selection);
|
|
29
|
+
const parentNode = findParentNodeOfType([nodes.blockquote, nodes.panel, nodes.expand, nodes.codeBlock, nodes.listItem, nodes.taskItem, nodes.layoutSection])(selection);
|
|
30
30
|
if (parentNode) {
|
|
31
31
|
nodeToFormat = parentNode.node;
|
|
32
32
|
nodePos = parentNode.pos;
|
|
33
|
-
|
|
33
|
+
const paragraphOrHeadingNode = findParentNodeOfType([nodes.paragraph, nodes.heading])(selection);
|
|
34
34
|
// Special case: if we found a listItem, check if we need the parent list instead
|
|
35
|
-
if (parentNode.node.type === nodes.listItem) {
|
|
35
|
+
if (parentNode.node.type === nodes.listItem || parentNode.node.type === nodes.taskItem) {
|
|
36
36
|
const listParent = findParentNodeOfType([nodes.bulletList, nodes.orderedList, nodes.taskList])(selection);
|
|
37
37
|
if (listParent) {
|
|
38
38
|
// For list transformations, we want the list parent, not the listItem
|
|
39
39
|
nodeToFormat = listParent.node;
|
|
40
40
|
nodePos = listParent.pos;
|
|
41
41
|
}
|
|
42
|
+
} else if (paragraphOrHeadingNode) {
|
|
43
|
+
nodeToFormat = paragraphOrHeadingNode.node;
|
|
44
|
+
nodePos = paragraphOrHeadingNode.pos;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
}
|