@atlaskit/editor-plugin-block-menu 1.0.1 → 1.0.3
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 +1 -1
- package/dist/cjs/editor-commands/transforms/container-transforms.js +60 -4
- package/dist/cjs/editor-commands/transforms/list/transformBetweenListTypes.js +22 -26
- 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/transformToTaskList.js +44 -0
- package/dist/cjs/editor-commands/transforms/list-transforms.js +19 -5
- 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 +1 -1
- package/dist/es2019/editor-commands/transforms/container-transforms.js +64 -4
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +24 -26
- 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/transformToTaskList.js +38 -0
- package/dist/es2019/editor-commands/transforms/list-transforms.js +20 -4
- 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 +1 -1
- package/dist/esm/editor-commands/transforms/container-transforms.js +60 -4
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +22 -26
- 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/transformToTaskList.js +37 -0
- package/dist/esm/editor-commands/transforms/list-transforms.js +18 -4
- 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 +1 -1
- 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/transformToTaskList.d.ts +10 -0
- package/dist/types/editor-commands/transforms/list-transforms.d.ts +4 -0
- package/dist/types-ts4.5/editor-commands/transforms/container-transforms.d.ts +1 -1
- 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/transformToTaskList.d.ts +10 -0
- package/dist/types-ts4.5/editor-commands/transforms/list-transforms.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3db18eece6c2f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3db18eece6c2f) -
|
|
8
|
+
[ux] Adds basic conversion from expand, panel, blockquote to bulled, numbered or task list.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 1.0.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`32434f817d714`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/32434f817d714) -
|
|
16
|
+
ED-29126: Convert list to block nodes
|
|
17
|
+
- [`255837cfba315`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/255837cfba315) -
|
|
18
|
+
Internal changes to how border radius is applied.
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 1.0.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -40,7 +40,7 @@ var formatNode = exports.formatNode = function formatNode(targetType) {
|
|
|
40
40
|
nodeToFormat = listParent.node;
|
|
41
41
|
nodePos = listParent.pos;
|
|
42
42
|
}
|
|
43
|
-
} else if (paragraphOrHeadingNode) {
|
|
43
|
+
} else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
|
|
44
44
|
nodeToFormat = paragraphOrHeadingNode.node;
|
|
45
45
|
nodePos = paragraphOrHeadingNode.pos;
|
|
46
46
|
}
|
|
@@ -50,6 +50,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
50
50
|
*/
|
|
51
51
|
var transformContainerNode = exports.transformContainerNode = function transformContainerNode(_ref2) {
|
|
52
52
|
var tr = _ref2.tr,
|
|
53
|
+
sourceNode = _ref2.sourceNode,
|
|
53
54
|
sourcePos = _ref2.sourcePos,
|
|
54
55
|
targetNodeType = _ref2.targetNodeType,
|
|
55
56
|
targetAttrs = _ref2.targetAttrs;
|
|
@@ -64,7 +65,13 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
64
65
|
|
|
65
66
|
// Transform container to list type
|
|
66
67
|
if ((0, _utils.isListNodeType)(targetNodeType)) {
|
|
67
|
-
return unwrapAndConvertToList(
|
|
68
|
+
return unwrapAndConvertToList({
|
|
69
|
+
tr: tr,
|
|
70
|
+
sourceNode: sourceNode,
|
|
71
|
+
sourcePos: sourcePos,
|
|
72
|
+
targetNodeType: targetNodeType,
|
|
73
|
+
targetAttrs: targetAttrs
|
|
74
|
+
});
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
// Transform between container types
|
|
@@ -86,7 +93,56 @@ var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function
|
|
|
86
93
|
/**
|
|
87
94
|
* Unwrap container node and convert content to list
|
|
88
95
|
*/
|
|
89
|
-
var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAndConvertToList() {
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
var unwrapAndConvertToList = exports.unwrapAndConvertToList = function unwrapAndConvertToList(_ref3) {
|
|
97
|
+
var tr = _ref3.tr,
|
|
98
|
+
sourceNode = _ref3.sourceNode,
|
|
99
|
+
sourcePos = _ref3.sourcePos,
|
|
100
|
+
targetNodeType = _ref3.targetNodeType,
|
|
101
|
+
targetAttrs = _ref3.targetAttrs;
|
|
102
|
+
if (sourcePos === null) {
|
|
103
|
+
return tr;
|
|
104
|
+
}
|
|
105
|
+
var schema = tr.doc.type.schema;
|
|
106
|
+
var _schema$nodes = schema.nodes,
|
|
107
|
+
listItem = _schema$nodes.listItem,
|
|
108
|
+
paragraph = _schema$nodes.paragraph,
|
|
109
|
+
taskList = _schema$nodes.taskList,
|
|
110
|
+
taskItem = _schema$nodes.taskItem;
|
|
111
|
+
var isTargetTaskList = targetNodeType === taskList;
|
|
112
|
+
var createListItemFromInline = function createListItemFromInline(inlineFrag) {
|
|
113
|
+
return isTargetTaskList ? taskItem.create(null, inlineFrag) : listItem.create(null, paragraph.create(null, inlineFrag));
|
|
114
|
+
};
|
|
115
|
+
var getInlineContent = function getInlineContent(textblock) {
|
|
116
|
+
var inlineContent = [];
|
|
117
|
+
textblock.forEach(function (inline) {
|
|
118
|
+
inlineContent.push(inline);
|
|
119
|
+
});
|
|
120
|
+
return inlineContent;
|
|
121
|
+
};
|
|
122
|
+
var items = [];
|
|
123
|
+
|
|
124
|
+
// Expand's title should become the first item of the list
|
|
125
|
+
if (sourceNode.type.name === 'expand') {
|
|
126
|
+
var _sourceNode$attrs;
|
|
127
|
+
var title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
|
|
128
|
+
if (title) {
|
|
129
|
+
var titleContent = schema.text(title);
|
|
130
|
+
items.push(isTargetTaskList ? taskItem.create(null, titleContent) : listItem.create(null, paragraph.create(null, titleContent)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (var i = 0; i < sourceNode.childCount; i++) {
|
|
134
|
+
var node = sourceNode.child(i);
|
|
135
|
+
|
|
136
|
+
// Abort early if unsupported content (e.g. table) encounted inside of the container
|
|
137
|
+
if (!node.isTextblock) {
|
|
138
|
+
return tr;
|
|
139
|
+
}
|
|
140
|
+
var inline = _model.Fragment.from(getInlineContent(node));
|
|
141
|
+
items.push(createListItemFromInline(inline));
|
|
142
|
+
}
|
|
143
|
+
if (!items.length) {
|
|
144
|
+
return tr;
|
|
145
|
+
}
|
|
146
|
+
var list = targetNodeType.create(targetAttrs || null, _model.Fragment.from(items));
|
|
147
|
+
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, list);
|
|
92
148
|
};
|
|
@@ -7,14 +7,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.transformListStructure = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Convert a block node to inline content suitable for task items
|
|
11
11
|
*/
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
var convertBlockToInlineContent = function convertBlockToInlineContent(node, schema) {
|
|
13
|
+
var paragraph = schema.nodes.paragraph;
|
|
14
|
+
if (node.type === paragraph) {
|
|
15
|
+
// Extract inline content from paragraphs
|
|
16
|
+
return (0, _toConsumableArray2.default)(node.content.content);
|
|
17
|
+
} else if (node.isBlock) {
|
|
18
|
+
// For other block content types eg. codeBlock, extract their text content and create text nodes
|
|
19
|
+
var textContent = node.textContent;
|
|
20
|
+
if (textContent) {
|
|
21
|
+
var textNode = schema.text(textContent);
|
|
22
|
+
return [textNode];
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
// Already inline content, add directly
|
|
26
|
+
return [node];
|
|
16
27
|
}
|
|
17
|
-
return
|
|
28
|
+
return [];
|
|
18
29
|
};
|
|
19
30
|
|
|
20
31
|
/**
|
|
@@ -48,25 +59,10 @@ var transformListStructure = exports.transformListStructure = function transform
|
|
|
48
59
|
// Extract inline content from all children within listItem
|
|
49
60
|
if (node.type === listItem) {
|
|
50
61
|
var inlineContent = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
}
|
|
62
|
+
// Extract inline content from all child nodes
|
|
63
|
+
node.forEach(function (child) {
|
|
64
|
+
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(convertBlockToInlineContent(child, tr.doc.type.schema)));
|
|
65
|
+
});
|
|
70
66
|
if (inlineContent.length > 0) {
|
|
71
67
|
var newItem = taskItem.create(null, inlineContent);
|
|
72
68
|
newListItems.push(newItem);
|
|
@@ -76,7 +72,7 @@ var transformListStructure = exports.transformListStructure = function transform
|
|
|
76
72
|
// Converting from task list to bullet/ordered list
|
|
77
73
|
// Structure: taskItem > inline content -> listItem > paragraph > inline content
|
|
78
74
|
if (node.type === taskItem) {
|
|
79
|
-
var _inlineContent =
|
|
75
|
+
var _inlineContent = (0, _toConsumableArray2.default)(node.content.content);
|
|
80
76
|
if (_inlineContent.length > 0) {
|
|
81
77
|
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
82
78
|
var newListItem = listItem.create(null, paragraphNode);
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.transformToTaskList = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
/**
|
|
10
|
+
* Transform selection to task list
|
|
11
|
+
* Handles the special structure where taskItem contains text directly (no paragraph wrapper)
|
|
12
|
+
*/
|
|
13
|
+
var transformToTaskList = exports.transformToTaskList = function transformToTaskList(tr, range, targetNodeType, targetAttrs, nodes) {
|
|
14
|
+
try {
|
|
15
|
+
var taskItem = nodes.taskItem;
|
|
16
|
+
var listItems = [];
|
|
17
|
+
|
|
18
|
+
// Process each block in the range
|
|
19
|
+
tr.doc.nodesBetween(range.start, range.end, function (node) {
|
|
20
|
+
if (node.isBlock) {
|
|
21
|
+
// For block nodes like paragraphs, directly use their inline content
|
|
22
|
+
var inlineContent = (0, _toConsumableArray2.default)(node.content.content);
|
|
23
|
+
if (inlineContent.length > 0) {
|
|
24
|
+
// Create task item with inline content directly
|
|
25
|
+
var listItem = taskItem.create(targetAttrs, inlineContent);
|
|
26
|
+
listItems.push(listItem);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false; // Don't traverse into children
|
|
30
|
+
});
|
|
31
|
+
if (listItems.length === 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Create the new task list
|
|
36
|
+
var newList = targetNodeType.create(targetAttrs, listItems);
|
|
37
|
+
|
|
38
|
+
// Replace the range with the new list
|
|
39
|
+
tr.replaceWith(range.start, range.end, newList);
|
|
40
|
+
return tr;
|
|
41
|
+
} catch (_unused) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.transformListNode = exports.transformBlockToList = exports.transformBetweenListTypes = exports.liftListToBlockType = void 0;
|
|
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
9
|
var _transformBetweenListTypes = require("./list/transformBetweenListTypes");
|
|
10
|
+
var _transformOrderedUnorderedListToBlockNodes = require("./list/transformOrderedUnorderedListToBlockNodes");
|
|
11
|
+
var _transformTaskListToBlockNodes = require("./list/transformTaskListToBlockNodes");
|
|
12
|
+
var _transformToTaskList = require("./list/transformToTaskList");
|
|
10
13
|
var _utils2 = require("./utils");
|
|
11
14
|
/**
|
|
12
15
|
* Transform selection to list type
|
|
13
16
|
*/
|
|
14
17
|
var transformBlockToList = exports.transformBlockToList = function transformBlockToList(context) {
|
|
15
18
|
var tr = context.tr,
|
|
19
|
+
sourceNode = context.sourceNode,
|
|
16
20
|
targetNodeType = context.targetNodeType,
|
|
17
21
|
targetAttrs = context.targetAttrs;
|
|
18
22
|
var _tr$selection = tr.selection,
|
|
@@ -26,13 +30,11 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
26
30
|
var isTargetTask = targetNodeType === nodes.taskList;
|
|
27
31
|
|
|
28
32
|
// Handle task lists differently due to their structure
|
|
29
|
-
// TODO: ED-29152 - Implement task list transformation
|
|
30
33
|
if (isTargetTask) {
|
|
31
|
-
return
|
|
34
|
+
return (0, _transformToTaskList.transformToTaskList)(tr, range, targetNodeType, targetAttrs, nodes);
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
35
|
-
var sourceNode = tr.doc.nodeAt(range.start);
|
|
36
38
|
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
37
39
|
tr.setBlockType(range.start, range.end, nodes.paragraph);
|
|
38
40
|
}
|
|
@@ -49,6 +51,18 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
49
51
|
return tr;
|
|
50
52
|
};
|
|
51
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
|
+
|
|
52
66
|
/**
|
|
53
67
|
* Transform list nodes
|
|
54
68
|
*/
|
|
@@ -57,7 +71,7 @@ var transformListNode = exports.transformListNode = function transformListNode(c
|
|
|
57
71
|
// Transform list to block type
|
|
58
72
|
if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
|
|
59
73
|
// Lift list items out of the list and convert to target block type
|
|
60
|
-
return
|
|
74
|
+
return transformListToBlockNodes(context);
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
// Transform list to container type
|
|
@@ -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;
|
|
@@ -39,7 +39,7 @@ export const formatNode = targetType => {
|
|
|
39
39
|
nodeToFormat = listParent.node;
|
|
40
40
|
nodePos = listParent.pos;
|
|
41
41
|
}
|
|
42
|
-
} else if (paragraphOrHeadingNode) {
|
|
42
|
+
} else if (parentNode.node.type !== nodes.blockquote && paragraphOrHeadingNode) {
|
|
43
43
|
nodeToFormat = paragraphOrHeadingNode.node;
|
|
44
44
|
nodePos = paragraphOrHeadingNode.pos;
|
|
45
45
|
}
|
|
@@ -45,6 +45,7 @@ export const transformToContainer = ({
|
|
|
45
45
|
*/
|
|
46
46
|
export const transformContainerNode = ({
|
|
47
47
|
tr,
|
|
48
|
+
sourceNode,
|
|
48
49
|
sourcePos,
|
|
49
50
|
targetNodeType,
|
|
50
51
|
targetAttrs
|
|
@@ -60,7 +61,13 @@ export const transformContainerNode = ({
|
|
|
60
61
|
|
|
61
62
|
// Transform container to list type
|
|
62
63
|
if (isListNodeType(targetNodeType)) {
|
|
63
|
-
return unwrapAndConvertToList(
|
|
64
|
+
return unwrapAndConvertToList({
|
|
65
|
+
tr,
|
|
66
|
+
sourceNode,
|
|
67
|
+
sourcePos,
|
|
68
|
+
targetNodeType,
|
|
69
|
+
targetAttrs
|
|
70
|
+
});
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
// Transform between container types
|
|
@@ -82,7 +89,60 @@ export const unwrapAndConvertToBlockType = () => {
|
|
|
82
89
|
/**
|
|
83
90
|
* Unwrap container node and convert content to list
|
|
84
91
|
*/
|
|
85
|
-
export const unwrapAndConvertToList = (
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
export const unwrapAndConvertToList = ({
|
|
93
|
+
tr,
|
|
94
|
+
sourceNode,
|
|
95
|
+
sourcePos,
|
|
96
|
+
targetNodeType,
|
|
97
|
+
targetAttrs
|
|
98
|
+
}) => {
|
|
99
|
+
if (sourcePos === null) {
|
|
100
|
+
return tr;
|
|
101
|
+
}
|
|
102
|
+
const {
|
|
103
|
+
schema
|
|
104
|
+
} = tr.doc.type;
|
|
105
|
+
const {
|
|
106
|
+
listItem,
|
|
107
|
+
paragraph,
|
|
108
|
+
taskList,
|
|
109
|
+
taskItem
|
|
110
|
+
} = schema.nodes;
|
|
111
|
+
const isTargetTaskList = targetNodeType === taskList;
|
|
112
|
+
const createListItemFromInline = inlineFrag => {
|
|
113
|
+
return isTargetTaskList ? taskItem.create(null, inlineFrag) : listItem.create(null, paragraph.create(null, inlineFrag));
|
|
114
|
+
};
|
|
115
|
+
const getInlineContent = textblock => {
|
|
116
|
+
const inlineContent = [];
|
|
117
|
+
textblock.forEach(inline => {
|
|
118
|
+
inlineContent.push(inline);
|
|
119
|
+
});
|
|
120
|
+
return inlineContent;
|
|
121
|
+
};
|
|
122
|
+
const items = [];
|
|
123
|
+
|
|
124
|
+
// Expand's title should become the first item of the list
|
|
125
|
+
if (sourceNode.type.name === 'expand') {
|
|
126
|
+
var _sourceNode$attrs;
|
|
127
|
+
const title = (_sourceNode$attrs = sourceNode.attrs) === null || _sourceNode$attrs === void 0 ? void 0 : _sourceNode$attrs.title;
|
|
128
|
+
if (title) {
|
|
129
|
+
const titleContent = schema.text(title);
|
|
130
|
+
items.push(isTargetTaskList ? taskItem.create(null, titleContent) : listItem.create(null, paragraph.create(null, titleContent)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (let i = 0; i < sourceNode.childCount; i++) {
|
|
134
|
+
const node = sourceNode.child(i);
|
|
135
|
+
|
|
136
|
+
// Abort early if unsupported content (e.g. table) encounted inside of the container
|
|
137
|
+
if (!node.isTextblock) {
|
|
138
|
+
return tr;
|
|
139
|
+
}
|
|
140
|
+
const inline = Fragment.from(getInlineContent(node));
|
|
141
|
+
items.push(createListItemFromInline(inline));
|
|
142
|
+
}
|
|
143
|
+
if (!items.length) {
|
|
144
|
+
return tr;
|
|
145
|
+
}
|
|
146
|
+
const list = targetNodeType.create(targetAttrs || null, Fragment.from(items));
|
|
147
|
+
return tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, list);
|
|
88
148
|
};
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Convert a block node to inline content suitable for task items
|
|
3
3
|
*/
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const convertBlockToInlineContent = (node, schema) => {
|
|
5
|
+
const {
|
|
6
|
+
paragraph
|
|
7
|
+
} = schema.nodes;
|
|
8
|
+
if (node.type === paragraph) {
|
|
9
|
+
// Extract inline content from paragraphs
|
|
10
|
+
return [...node.content.content];
|
|
11
|
+
} else if (node.isBlock) {
|
|
12
|
+
// For other block content types eg. codeBlock, extract their text content and create text nodes
|
|
13
|
+
const textContent = node.textContent;
|
|
14
|
+
if (textContent) {
|
|
15
|
+
const textNode = schema.text(textContent);
|
|
16
|
+
return [textNode];
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
// Already inline content, add directly
|
|
20
|
+
return [node];
|
|
8
21
|
}
|
|
9
|
-
return
|
|
22
|
+
return [];
|
|
10
23
|
};
|
|
11
24
|
|
|
12
25
|
/**
|
|
@@ -44,25 +57,10 @@ export const transformListStructure = (tr, listNode, targetNodeType, nodes) => {
|
|
|
44
57
|
// Extract inline content from all children within listItem
|
|
45
58
|
if (node.type === listItem) {
|
|
46
59
|
const inlineContent = [];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (child.type === paragraph) {
|
|
52
|
-
// Extract inline content from paragraphs
|
|
53
|
-
inlineContent.push(...extractInlineContent(child));
|
|
54
|
-
} else if (child.isBlock) {
|
|
55
|
-
// For other block content types eg. codeBlock, extract their text content and create text nodes
|
|
56
|
-
const textContent = child.textContent;
|
|
57
|
-
if (textContent) {
|
|
58
|
-
const textNode = tr.doc.type.schema.text(textContent);
|
|
59
|
-
inlineContent.push(textNode);
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
// Already inline content, add directly
|
|
63
|
-
inlineContent.push(child);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
60
|
+
// Extract inline content from all child nodes
|
|
61
|
+
node.forEach(child => {
|
|
62
|
+
inlineContent.push(...convertBlockToInlineContent(child, tr.doc.type.schema));
|
|
63
|
+
});
|
|
66
64
|
if (inlineContent.length > 0) {
|
|
67
65
|
const newItem = taskItem.create(null, inlineContent);
|
|
68
66
|
newListItems.push(newItem);
|
|
@@ -72,7 +70,7 @@ export const transformListStructure = (tr, listNode, targetNodeType, nodes) => {
|
|
|
72
70
|
// Converting from task list to bullet/ordered list
|
|
73
71
|
// Structure: taskItem > inline content -> listItem > paragraph > inline content
|
|
74
72
|
if (node.type === taskItem) {
|
|
75
|
-
const inlineContent =
|
|
73
|
+
const inlineContent = [...node.content.content];
|
|
76
74
|
if (inlineContent.length > 0) {
|
|
77
75
|
const paragraphNode = paragraph.create(null, inlineContent);
|
|
78
76
|
const newListItem = listItem.create(null, paragraphNode);
|
package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
export const transformOrderedUnorderedListToBlockNodes = context => {
|
|
4
|
+
const {
|
|
5
|
+
tr,
|
|
6
|
+
targetNodeType,
|
|
7
|
+
targetAttrs,
|
|
8
|
+
sourceNode,
|
|
9
|
+
sourcePos
|
|
10
|
+
} = context;
|
|
11
|
+
const {
|
|
12
|
+
selection
|
|
13
|
+
} = tr;
|
|
14
|
+
const schema = selection.$from.doc.type.schema;
|
|
15
|
+
// find all paragraph nodes inside the list node
|
|
16
|
+
const paragraphs = findChildrenByType(sourceNode, schema.nodes.paragraph);
|
|
17
|
+
const paragraphNodes = paragraphs.map(paragraph => paragraph.node);
|
|
18
|
+
let targetNodes = paragraphNodes;
|
|
19
|
+
|
|
20
|
+
// Convert paragraphs to headings if target is heading
|
|
21
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
22
|
+
const targetHeadingLevel = targetAttrs.level;
|
|
23
|
+
targetNodes = paragraphNodes.map(paragraphNode => schema.nodes.heading.createChecked({
|
|
24
|
+
level: targetHeadingLevel
|
|
25
|
+
}, paragraphNode.content));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Convert paragraphs to code block if target is code block
|
|
29
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
30
|
+
// convert the paragraphNodes to one code block
|
|
31
|
+
const listItemsResult = findChildrenByType(sourceNode, schema.nodes.listItem);
|
|
32
|
+
const listItems = listItemsResult.map(item => item.node);
|
|
33
|
+
const listItemFragments = listItems.map(listItem => listItem.content);
|
|
34
|
+
const codeBlockContent = listItemFragments.map(fragment => fragment.textBetween(0, fragment.size, '\n')).join('\n');
|
|
35
|
+
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
36
|
+
}
|
|
37
|
+
const fragment = Fragment.fromArray(targetNodes);
|
|
38
|
+
const slice = new Slice(fragment, 0, 0);
|
|
39
|
+
const rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
40
|
+
tr.replaceRange(rangeStart, rangeStart + sourceNode.nodeSize, slice);
|
|
41
|
+
return tr;
|
|
42
|
+
};
|