@atlaskit/editor-plugin-block-menu 5.2.9 → 5.2.11
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 +14 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/cjs/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -4
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +40 -4
- package/dist/cjs/editor-commands/transform-node-utils/wrapStep.js +20 -1
- package/dist/cjs/ui/block-menu-components.js +30 -20
- package/dist/cjs/ui/hooks/useSuggestedItems.js +57 -0
- package/dist/cjs/ui/suggested-items-menu-section.js +21 -0
- package/dist/cjs/ui/suggested-menu-items.js +19 -0
- package/dist/cjs/ui/utils/suggested-items-rank.js +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/es2019/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -2
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +39 -3
- package/dist/es2019/editor-commands/transform-node-utils/wrapStep.js +21 -1
- package/dist/es2019/ui/block-menu-components.js +12 -4
- package/dist/es2019/ui/hooks/useSuggestedItems.js +45 -0
- package/dist/es2019/ui/suggested-items-menu-section.js +15 -0
- package/dist/es2019/ui/suggested-menu-items.js +13 -0
- package/dist/es2019/ui/utils/suggested-items-rank.js +31 -43
- package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
- package/dist/esm/editor-commands/transform-node-utils/transform.js +2 -2
- package/dist/esm/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -3
- package/dist/esm/editor-commands/transform-node-utils/utils.js +39 -3
- package/dist/esm/editor-commands/transform-node-utils/wrapStep.js +21 -1
- package/dist/esm/ui/block-menu-components.js +30 -20
- package/dist/esm/ui/hooks/useSuggestedItems.js +51 -0
- package/dist/esm/ui/suggested-items-menu-section.js +14 -0
- package/dist/esm/ui/suggested-menu-items.js +12 -0
- package/dist/esm/ui/utils/suggested-items-rank.js +2 -2
- package/dist/types/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +5 -0
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +17 -0
- package/dist/types/editor-commands/transform-node-utils/wrapStep.d.ts +5 -0
- package/dist/types/ui/hooks/useSuggestedItems.d.ts +3 -0
- package/dist/types/ui/suggested-items-menu-section.d.ts +9 -0
- package/dist/{types-ts4.5/ui/suggested-items-renderer.d.ts → types/ui/suggested-menu-items.d.ts} +2 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +5 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +17 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapStep.d.ts +5 -0
- package/dist/types-ts4.5/ui/hooks/useSuggestedItems.d.ts +3 -0
- package/dist/types-ts4.5/ui/suggested-items-menu-section.d.ts +9 -0
- package/dist/{types/ui/suggested-items-renderer.d.ts → types-ts4.5/ui/suggested-menu-items.d.ts} +2 -2
- package/package.json +4 -4
- package/dist/cjs/ui/suggested-items-renderer.js +0 -62
- package/dist/es2019/ui/suggested-items-renderer.js +0 -48
- package/dist/esm/ui/suggested-items-renderer.js +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.2.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0c673432d72e9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0c673432d72e9) -
|
|
8
|
+
[ux] Fix bug / make wrap of expand convert to nestedExpand node
|
|
9
|
+
|
|
10
|
+
## 5.2.10
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`eb116a739e7c2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eb116a739e7c2) -
|
|
15
|
+
[ux] Fix bug / make unwrap of expand convert nestedExpand node to regular expand node
|
|
16
|
+
|
|
3
17
|
## 5.2.9
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -48,21 +48,6 @@ var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeT
|
|
|
48
48
|
return targetNodeType.validContent(_model.Fragment.from(node));
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
* Converts a nestedExpand to a regular expand node.
|
|
53
|
-
* NestedExpands can only exist inside expands, so when breaking out they must be converted.
|
|
54
|
-
*/
|
|
55
|
-
var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
|
|
56
|
-
var _node$attrs;
|
|
57
|
-
var expandType = schema.nodes.expand;
|
|
58
|
-
if (!expandType) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
return expandType.createAndFill({
|
|
62
|
-
title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
|
|
63
|
-
}, node.content);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
51
|
/**
|
|
67
52
|
* A wrap step that handles mixed content according to the Compatibility Matrix:
|
|
68
53
|
* - Wraps consecutive compatible nodes into the target container
|
|
@@ -108,14 +93,6 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
|
|
|
108
93
|
// This handles: "If there's a panel in the expand, it breaks out into a separate panel"
|
|
109
94
|
flushCurrentContainer();
|
|
110
95
|
result.push(node);
|
|
111
|
-
} else if (node.type.name === 'nestedExpand') {
|
|
112
|
-
// NestedExpand can't be wrapped and can't exist outside an expand
|
|
113
|
-
// Convert to regular expand and break out
|
|
114
|
-
flushCurrentContainer();
|
|
115
|
-
var expandNode = convertNestedExpandToExpand(node, schema);
|
|
116
|
-
if (expandNode) {
|
|
117
|
-
result.push(expandNode);
|
|
118
|
-
}
|
|
119
96
|
} else if (isTextNode(node)) {
|
|
120
97
|
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
121
98
|
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
@@ -89,9 +89,9 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
89
89
|
decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
|
|
90
90
|
},
|
|
91
91
|
layoutSection: {
|
|
92
|
-
blockquote: [_unwrapLayoutStep.unwrapLayoutStep,
|
|
92
|
+
blockquote: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
93
93
|
expand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
|
|
94
|
-
panel: [_unwrapLayoutStep.unwrapLayoutStep,
|
|
94
|
+
panel: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
95
95
|
codeBlock: [_unwrapLayoutStep.unwrapLayoutStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
|
|
96
96
|
paragraph: [_unwrapLayoutStep.unwrapLayoutStep]
|
|
97
97
|
},
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.unwrapExpandStep = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
7
|
var _unwrapStep = require("./unwrapStep");
|
|
8
|
+
var _utils = require("./utils");
|
|
10
9
|
/**
|
|
11
10
|
* Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
|
|
12
11
|
* and prepending it to the children.
|
|
13
12
|
*
|
|
13
|
+
* Any nestedExpand children are converted to regular expands since nestedExpand
|
|
14
|
+
* can only exist inside an expand.
|
|
15
|
+
*
|
|
14
16
|
* Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
|
|
17
|
+
* Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
|
|
18
|
+
* → [p('outer'), expand({ title: 'inner' })(p('x'))]
|
|
15
19
|
*/
|
|
16
20
|
var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(nodes, context) {
|
|
17
21
|
var schema = context.schema;
|
|
@@ -33,8 +37,20 @@ var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(node
|
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
// Add the children
|
|
37
|
-
|
|
40
|
+
// Add the children, converting any nestedExpands to regular expands
|
|
41
|
+
// since nestedExpand can only exist inside an expand
|
|
42
|
+
node.children.forEach(function (child) {
|
|
43
|
+
if (child.type.name === nestedExpand.name) {
|
|
44
|
+
var expandNode = (0, _utils.convertNestedExpandToExpand)(child, schema);
|
|
45
|
+
if (expandNode) {
|
|
46
|
+
outputNodes.push(expandNode);
|
|
47
|
+
} else {
|
|
48
|
+
outputNodes.push(child);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
outputNodes.push(child);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
38
54
|
} else {
|
|
39
55
|
(0, _unwrapStep.unwrapStep)([node], context);
|
|
40
56
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isListType = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.expandSelectionToBlockRange = void 0;
|
|
6
|
+
exports.isListType = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.expandSelectionToBlockRange = exports.convertNestedExpandToExpand = exports.convertExpandToNestedExpand = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
9
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
@@ -67,7 +67,7 @@ var getTargetNodeTypeNameInContext = exports.getTargetNodeTypeNameInContext = fu
|
|
|
67
67
|
*/
|
|
68
68
|
var expandSelectionToBlockRange = exports.expandSelectionToBlockRange = function expandSelectionToBlockRange(selection, schema) {
|
|
69
69
|
var nodes = schema.nodes;
|
|
70
|
-
var nodesNeedToExpandRange = [nodes.listItem, nodes.taskItem];
|
|
70
|
+
var nodesNeedToExpandRange = [nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.listItem, nodes.taskItem];
|
|
71
71
|
|
|
72
72
|
// when adding nodes.tableRow, tableHeader, tableCell in nodesNeedToExpandRang,
|
|
73
73
|
// expandToBlockRange does not return expected table start position, sometimes even freeze editor
|
|
@@ -76,10 +76,11 @@ var expandSelectionToBlockRange = exports.expandSelectionToBlockRange = function
|
|
|
76
76
|
var table = (0, _utils2.findTable)(selection);
|
|
77
77
|
if (table) {
|
|
78
78
|
var $from = selection.$from.doc.resolve(table.pos);
|
|
79
|
-
var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize);
|
|
79
|
+
var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
|
|
80
80
|
return {
|
|
81
81
|
$from: $from,
|
|
82
|
-
$to: $to
|
|
82
|
+
$to: $to,
|
|
83
|
+
range: $from.blockRange($to)
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -112,7 +113,42 @@ var isListType = exports.isListType = function isListType(node, schema) {
|
|
|
112
113
|
return list === node.type;
|
|
113
114
|
});
|
|
114
115
|
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Converts a nestedExpand to a regular expand node.
|
|
119
|
+
* NestedExpands can only exist inside expands, so when breaking out or placing
|
|
120
|
+
* in containers that don't support nesting, they must be converted.
|
|
121
|
+
*/
|
|
122
|
+
var convertNestedExpandToExpand = exports.convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
|
|
123
|
+
var _node$attrs;
|
|
124
|
+
var expandType = schema.nodes.expand;
|
|
125
|
+
if (!expandType) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return expandType.createAndFill({
|
|
129
|
+
title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
|
|
130
|
+
}, node.content);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Converts an expand to a nestedExpand node.
|
|
135
|
+
* When placing an expand inside another expand, it must become a nestedExpand
|
|
136
|
+
* since expand cannot be a direct child of expand.
|
|
137
|
+
*/
|
|
138
|
+
var convertExpandToNestedExpand = exports.convertExpandToNestedExpand = function convertExpandToNestedExpand(node, schema) {
|
|
139
|
+
var _node$attrs2;
|
|
140
|
+
var nestedExpandType = schema.nodes.nestedExpand;
|
|
141
|
+
if (!nestedExpandType) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return nestedExpandType.createAndFill({
|
|
145
|
+
title: ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.title) || ''
|
|
146
|
+
}, node.content);
|
|
147
|
+
};
|
|
115
148
|
var getBlockNodesInRange = exports.getBlockNodesInRange = function getBlockNodesInRange(range) {
|
|
149
|
+
if (range.startIndex === range.endIndex) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
116
152
|
if (range.endIndex - range.startIndex <= 1) {
|
|
117
153
|
return [range.parent.child(range.startIndex)];
|
|
118
154
|
}
|
|
@@ -4,10 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.wrapStep = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* Wraps nodes into the target container type.
|
|
10
|
+
* When wrapping into expand, any expand children are converted to nestedExpand
|
|
11
|
+
* since expand cannot be a direct child of expand.
|
|
12
|
+
*/
|
|
7
13
|
var wrapStep = exports.wrapStep = function wrapStep(nodes, context) {
|
|
8
14
|
var schema = context.schema,
|
|
9
15
|
targetNodeTypeName = context.targetNodeTypeName;
|
|
10
|
-
|
|
16
|
+
|
|
17
|
+
// When wrapping into expand, convert any expand children to nestedExpand
|
|
18
|
+
// since expand cannot be a direct child of expand
|
|
19
|
+
var processedNodes = nodes;
|
|
20
|
+
if (targetNodeTypeName === 'expand') {
|
|
21
|
+
processedNodes = nodes.map(function (node) {
|
|
22
|
+
if (node.type.name === 'expand') {
|
|
23
|
+
var nestedExpandNode = (0, _utils.convertExpandToNestedExpand)(node, schema);
|
|
24
|
+
return nestedExpandNode !== null && nestedExpandNode !== void 0 ? nestedExpandNode : node;
|
|
25
|
+
}
|
|
26
|
+
return node;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, processedNodes);
|
|
11
30
|
if (outputNode) {
|
|
12
31
|
return [outputNode];
|
|
13
32
|
}
|
|
@@ -17,7 +17,8 @@ var _formatMenuNested = require("./format-menu-nested");
|
|
|
17
17
|
var _formatMenuSection = require("./format-menu-section");
|
|
18
18
|
var _moveDown = require("./move-down");
|
|
19
19
|
var _moveUp = require("./move-up");
|
|
20
|
-
var
|
|
20
|
+
var _suggestedItemsMenuSection = require("./suggested-items-menu-section");
|
|
21
|
+
var _suggestedMenuItems = require("./suggested-menu-items");
|
|
21
22
|
var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
|
|
22
23
|
return [{
|
|
23
24
|
type: 'block-menu-item',
|
|
@@ -74,9 +75,13 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
74
75
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION.key]
|
|
75
76
|
},
|
|
76
77
|
component: function component() {
|
|
77
|
-
|
|
78
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
79
|
+
children: null
|
|
80
|
+
},
|
|
81
|
+
children = _ref2.children;
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement(_suggestedItemsMenuSection.SuggestedItemsMenuSection, {
|
|
78
83
|
api: api
|
|
79
|
-
});
|
|
84
|
+
}, children);
|
|
80
85
|
}
|
|
81
86
|
}, {
|
|
82
87
|
type: 'block-menu-item',
|
|
@@ -85,6 +90,11 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
85
90
|
type: 'block-menu-section',
|
|
86
91
|
key: _blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION.key,
|
|
87
92
|
rank: _blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION_RANK[_blockMenu.TRANSFORM_SUGGESTED_MENU_ITEM.key]
|
|
93
|
+
},
|
|
94
|
+
component: function component() {
|
|
95
|
+
return /*#__PURE__*/_react.default.createElement(_suggestedMenuItems.SuggestedMenuItems, {
|
|
96
|
+
api: api
|
|
97
|
+
});
|
|
88
98
|
}
|
|
89
99
|
}, {
|
|
90
100
|
type: 'block-menu-section',
|
|
@@ -95,10 +105,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
95
105
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
|
|
96
106
|
},
|
|
97
107
|
component: function component() {
|
|
98
|
-
var
|
|
108
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
99
109
|
children: null
|
|
100
110
|
},
|
|
101
|
-
children =
|
|
111
|
+
children = _ref3.children;
|
|
102
112
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
103
113
|
title: "Create"
|
|
104
114
|
}, children);
|
|
@@ -112,10 +122,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
112
122
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key]
|
|
113
123
|
},
|
|
114
124
|
component: function component() {
|
|
115
|
-
var
|
|
125
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
116
126
|
children: null
|
|
117
127
|
},
|
|
118
|
-
children =
|
|
128
|
+
children = _ref4.children;
|
|
119
129
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
120
130
|
title: "Structure"
|
|
121
131
|
}, children);
|
|
@@ -129,10 +139,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
129
139
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_HEADINGS_MENU_SECTION.key]
|
|
130
140
|
},
|
|
131
141
|
component: function component() {
|
|
132
|
-
var
|
|
142
|
+
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
133
143
|
children: null
|
|
134
144
|
},
|
|
135
|
-
children =
|
|
145
|
+
children = _ref5.children;
|
|
136
146
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
137
147
|
title: "Headings",
|
|
138
148
|
hasSeparator: true
|
|
@@ -142,23 +152,23 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
142
152
|
type: 'block-menu-section',
|
|
143
153
|
key: _blockMenu.TRANSFORM_MENU_SECTION.key,
|
|
144
154
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.TRANSFORM_MENU_SECTION.key],
|
|
145
|
-
component: function component(
|
|
146
|
-
var children =
|
|
155
|
+
component: function component(_ref6) {
|
|
156
|
+
var children = _ref6.children;
|
|
147
157
|
return /*#__PURE__*/_react.default.createElement(_formatMenuSection.FormatMenuSection, {
|
|
148
158
|
api: api
|
|
149
159
|
}, children);
|
|
150
160
|
}
|
|
151
161
|
}];
|
|
152
162
|
};
|
|
153
|
-
var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(
|
|
154
|
-
var api =
|
|
155
|
-
config =
|
|
163
|
+
var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(_ref7) {
|
|
164
|
+
var api = _ref7.api,
|
|
165
|
+
config = _ref7.config;
|
|
156
166
|
return [].concat((0, _toConsumableArray2.default)(getTurnIntoMenuComponents(api)), [{
|
|
157
167
|
type: 'block-menu-section',
|
|
158
168
|
key: _blockMenu.BLOCK_ACTIONS_MENU_SECTION.key,
|
|
159
169
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.BLOCK_ACTIONS_MENU_SECTION.key],
|
|
160
|
-
component: function component(
|
|
161
|
-
var children =
|
|
170
|
+
component: function component(_ref8) {
|
|
171
|
+
var children = _ref8.children;
|
|
162
172
|
return /*#__PURE__*/_react.default.createElement(_copySection.CopySection, {
|
|
163
173
|
api: api
|
|
164
174
|
}, children);
|
|
@@ -181,8 +191,8 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
|
|
|
181
191
|
type: 'block-menu-section',
|
|
182
192
|
key: _blockMenu.POSITION_MENU_SECTION.key,
|
|
183
193
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.POSITION_MENU_SECTION.key],
|
|
184
|
-
component: function component(
|
|
185
|
-
var children =
|
|
194
|
+
component: function component(_ref9) {
|
|
195
|
+
var children = _ref9.children;
|
|
186
196
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
187
197
|
hasSeparator: true
|
|
188
198
|
}, children);
|
|
@@ -191,8 +201,8 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
|
|
|
191
201
|
type: 'block-menu-section',
|
|
192
202
|
key: _blockMenu.DELETE_MENU_SECTION.key,
|
|
193
203
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.DELETE_MENU_SECTION.key],
|
|
194
|
-
component: function component(
|
|
195
|
-
var children =
|
|
204
|
+
component: function component(_ref0) {
|
|
205
|
+
var children = _ref0.children;
|
|
196
206
|
return /*#__PURE__*/_react.default.createElement(_deleteSection.DeleteSection, {
|
|
197
207
|
api: api
|
|
198
208
|
}, children);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSuggestedItems = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
9
|
+
var _utils = require("../../editor-commands/transform-node-utils/utils");
|
|
10
|
+
var _suggestedItemsRank = require("../utils/suggested-items-rank");
|
|
11
|
+
var useSuggestedItems = exports.useSuggestedItems = function useSuggestedItems(api) {
|
|
12
|
+
var _api$blockMenu;
|
|
13
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls', 'selection'], function (states) {
|
|
14
|
+
var _states$blockControls, _states$selectionStat;
|
|
15
|
+
return {
|
|
16
|
+
preservedSelection: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.preservedSelection,
|
|
17
|
+
selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
preservedSelection = _useSharedPluginState.preservedSelection,
|
|
21
|
+
selection = _useSharedPluginState.selection;
|
|
22
|
+
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
23
|
+
var menuItemsMap = (0, _react.useMemo)(function () {
|
|
24
|
+
if (!blockMenuComponents) {
|
|
25
|
+
return new Map();
|
|
26
|
+
}
|
|
27
|
+
return new Map(blockMenuComponents.filter(function (c) {
|
|
28
|
+
return c.type === 'block-menu-item';
|
|
29
|
+
}).map(function (item) {
|
|
30
|
+
return [item.key, item];
|
|
31
|
+
}));
|
|
32
|
+
}, [blockMenuComponents]);
|
|
33
|
+
var suggestedItems = (0, _react.useMemo)(function () {
|
|
34
|
+
var currentSelection = preservedSelection || selection;
|
|
35
|
+
if (menuItemsMap.size === 0 || !currentSelection) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
var _expandSelectionToBlo = (0, _utils.expandSelectionToBlockRange)(currentSelection, currentSelection.$from.doc.type.schema),
|
|
39
|
+
range = _expandSelectionToBlo.range;
|
|
40
|
+
if (!range) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
var blockNodes = (0, _utils.getBlockNodesInRange)(range);
|
|
44
|
+
var singleNode = blockNodes.length === 1 ? blockNodes[0] : undefined;
|
|
45
|
+
if (!singleNode) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
var nodeTypeName = singleNode.type.name;
|
|
49
|
+
var sortedKeys = (0, _suggestedItemsRank.getSortedSuggestedItems)(nodeTypeName);
|
|
50
|
+
return sortedKeys.map(function (key) {
|
|
51
|
+
return menuItemsMap.get(key);
|
|
52
|
+
}).filter(function (item) {
|
|
53
|
+
return item !== undefined;
|
|
54
|
+
});
|
|
55
|
+
}, [menuItemsMap, preservedSelection, selection]);
|
|
56
|
+
return suggestedItems;
|
|
57
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SuggestedItemsMenuSection = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
10
|
+
var _useSuggestedItems = require("./hooks/useSuggestedItems");
|
|
11
|
+
var SuggestedItemsMenuSection = exports.SuggestedItemsMenuSection = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
12
|
+
var api = _ref.api,
|
|
13
|
+
children = _ref.children;
|
|
14
|
+
var suggestedItems = (0, _useSuggestedItems.useSuggestedItems)(api);
|
|
15
|
+
if (suggestedItems.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
19
|
+
title: "Suggested"
|
|
20
|
+
}, children);
|
|
21
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SuggestedMenuItems = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _useSuggestedItems = require("./hooks/useSuggestedItems");
|
|
10
|
+
var SuggestedMenuItems = exports.SuggestedMenuItems = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
11
|
+
var api = _ref.api;
|
|
12
|
+
var suggestedItems = (0, _useSuggestedItems.useSuggestedItems)(api);
|
|
13
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, suggestedItems.map(function (item) {
|
|
14
|
+
var ItemComponent = item.component;
|
|
15
|
+
return ItemComponent ? /*#__PURE__*/_react.default.createElement(ItemComponent, {
|
|
16
|
+
key: item.key
|
|
17
|
+
}) : null;
|
|
18
|
+
}));
|
|
19
|
+
});
|
|
@@ -43,7 +43,7 @@ var BLOCK_MENU_NODE_TYPES = exports.BLOCK_MENU_NODE_TYPES = {
|
|
|
43
43
|
EMBED_CARD: 'embedCard',
|
|
44
44
|
TABLE: 'table'
|
|
45
45
|
};
|
|
46
|
-
var TRANSFORM_SUGGESTED_ITEMS_RANK = exports.TRANSFORM_SUGGESTED_ITEMS_RANK = (_TRANSFORM_SUGGESTED_ = {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_TRANSFORM_SUGGESTED_, BLOCK_MENU_NODE_TYPES.PARAGRAPH, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.
|
|
46
|
+
var TRANSFORM_SUGGESTED_ITEMS_RANK = exports.TRANSFORM_SUGGESTED_ITEMS_RANK = (_TRANSFORM_SUGGESTED_ = {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_TRANSFORM_SUGGESTED_, BLOCK_MENU_NODE_TYPES.PARAGRAPH, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_HEADINGS_H1_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_HEADINGS_H2_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.EXPAND, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.BLOCKQUOTE, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.LAYOUT_SECTION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.PANEL, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.CODE_BLOCK, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.DECISION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.BULLET_LIST, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.ORDERED_LIST, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.HEADING, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 300)), (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_TRANSFORM_SUGGESTED_, BLOCK_MENU_NODE_TYPES.TASK_LIST, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.MEDIA_SINGLE, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.EXTENSION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.BODIED_EXTENSION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 300)));
|
|
47
47
|
var getSuggestedItemsForNodeType = exports.getSuggestedItemsForNodeType = function getSuggestedItemsForNodeType(nodeType) {
|
|
48
48
|
return TRANSFORM_SUGGESTED_ITEMS_RANK[nodeType];
|
|
49
49
|
};
|
|
@@ -43,21 +43,6 @@ const canWrapInTarget = (node, targetNodeType, targetNodeTypeName) => {
|
|
|
43
43
|
return targetNodeType.validContent(Fragment.from(node));
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* Converts a nestedExpand to a regular expand node.
|
|
48
|
-
* NestedExpands can only exist inside expands, so when breaking out they must be converted.
|
|
49
|
-
*/
|
|
50
|
-
const convertNestedExpandToExpand = (node, schema) => {
|
|
51
|
-
var _node$attrs;
|
|
52
|
-
const expandType = schema.nodes.expand;
|
|
53
|
-
if (!expandType) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return expandType.createAndFill({
|
|
57
|
-
title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
|
|
58
|
-
}, node.content);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
46
|
/**
|
|
62
47
|
* A wrap step that handles mixed content according to the Compatibility Matrix:
|
|
63
48
|
* - Wraps consecutive compatible nodes into the target container
|
|
@@ -105,14 +90,6 @@ export const wrapMixedContentStep = (nodes, context) => {
|
|
|
105
90
|
// This handles: "If there's a panel in the expand, it breaks out into a separate panel"
|
|
106
91
|
flushCurrentContainer();
|
|
107
92
|
result.push(node);
|
|
108
|
-
} else if (node.type.name === 'nestedExpand') {
|
|
109
|
-
// NestedExpand can't be wrapped and can't exist outside an expand
|
|
110
|
-
// Convert to regular expand and break out
|
|
111
|
-
flushCurrentContainer();
|
|
112
|
-
const expandNode = convertNestedExpandToExpand(node, schema);
|
|
113
|
-
if (expandNode) {
|
|
114
|
-
result.push(expandNode);
|
|
115
|
-
}
|
|
116
93
|
} else if (isTextNode(node)) {
|
|
117
94
|
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
118
95
|
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
@@ -84,9 +84,9 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
84
84
|
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep]
|
|
85
85
|
},
|
|
86
86
|
layoutSection: {
|
|
87
|
-
blockquote: [unwrapLayoutStep,
|
|
87
|
+
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
88
88
|
expand: [unwrapLayoutStep, wrapStep],
|
|
89
|
-
panel: [unwrapLayoutStep,
|
|
89
|
+
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
90
90
|
codeBlock: [unwrapLayoutStep, flattenStep, wrapStep],
|
|
91
91
|
paragraph: [unwrapLayoutStep]
|
|
92
92
|
},
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { unwrapStep } from './unwrapStep';
|
|
2
|
+
import { convertNestedExpandToExpand } from './utils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
|
|
5
6
|
* and prepending it to the children.
|
|
6
7
|
*
|
|
8
|
+
* Any nestedExpand children are converted to regular expands since nestedExpand
|
|
9
|
+
* can only exist inside an expand.
|
|
10
|
+
*
|
|
7
11
|
* Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
|
|
12
|
+
* Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
|
|
13
|
+
* → [p('outer'), expand({ title: 'inner' })(p('x'))]
|
|
8
14
|
*/
|
|
9
15
|
export const unwrapExpandStep = (nodes, context) => {
|
|
10
16
|
const {
|
|
@@ -29,8 +35,20 @@ export const unwrapExpandStep = (nodes, context) => {
|
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
// Add the children
|
|
33
|
-
|
|
38
|
+
// Add the children, converting any nestedExpands to regular expands
|
|
39
|
+
// since nestedExpand can only exist inside an expand
|
|
40
|
+
node.children.forEach(child => {
|
|
41
|
+
if (child.type.name === nestedExpand.name) {
|
|
42
|
+
const expandNode = convertNestedExpandToExpand(child, schema);
|
|
43
|
+
if (expandNode) {
|
|
44
|
+
outputNodes.push(expandNode);
|
|
45
|
+
} else {
|
|
46
|
+
outputNodes.push(child);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
outputNodes.push(child);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
34
52
|
} else {
|
|
35
53
|
unwrapStep([node], context);
|
|
36
54
|
}
|
|
@@ -64,7 +64,7 @@ export const expandSelectionToBlockRange = (selection, schema) => {
|
|
|
64
64
|
const {
|
|
65
65
|
nodes
|
|
66
66
|
} = schema;
|
|
67
|
-
const nodesNeedToExpandRange = [nodes.listItem, nodes.taskItem];
|
|
67
|
+
const nodesNeedToExpandRange = [nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.listItem, nodes.taskItem];
|
|
68
68
|
|
|
69
69
|
// when adding nodes.tableRow, tableHeader, tableCell in nodesNeedToExpandRang,
|
|
70
70
|
// expandToBlockRange does not return expected table start position, sometimes even freeze editor
|
|
@@ -73,10 +73,11 @@ export const expandSelectionToBlockRange = (selection, schema) => {
|
|
|
73
73
|
const table = findTable(selection);
|
|
74
74
|
if (table) {
|
|
75
75
|
const $from = selection.$from.doc.resolve(table.pos);
|
|
76
|
-
const $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize);
|
|
76
|
+
const $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
|
|
77
77
|
return {
|
|
78
78
|
$from,
|
|
79
|
-
$to
|
|
79
|
+
$to,
|
|
80
|
+
range: $from.blockRange($to)
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -107,7 +108,42 @@ export const isListType = (node, schema) => {
|
|
|
107
108
|
const lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
|
|
108
109
|
return lists.some(list => list === node.type);
|
|
109
110
|
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts a nestedExpand to a regular expand node.
|
|
114
|
+
* NestedExpands can only exist inside expands, so when breaking out or placing
|
|
115
|
+
* in containers that don't support nesting, they must be converted.
|
|
116
|
+
*/
|
|
117
|
+
export const convertNestedExpandToExpand = (node, schema) => {
|
|
118
|
+
var _node$attrs;
|
|
119
|
+
const expandType = schema.nodes.expand;
|
|
120
|
+
if (!expandType) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return expandType.createAndFill({
|
|
124
|
+
title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
|
|
125
|
+
}, node.content);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Converts an expand to a nestedExpand node.
|
|
130
|
+
* When placing an expand inside another expand, it must become a nestedExpand
|
|
131
|
+
* since expand cannot be a direct child of expand.
|
|
132
|
+
*/
|
|
133
|
+
export const convertExpandToNestedExpand = (node, schema) => {
|
|
134
|
+
var _node$attrs2;
|
|
135
|
+
const nestedExpandType = schema.nodes.nestedExpand;
|
|
136
|
+
if (!nestedExpandType) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return nestedExpandType.createAndFill({
|
|
140
|
+
title: ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.title) || ''
|
|
141
|
+
}, node.content);
|
|
142
|
+
};
|
|
110
143
|
export const getBlockNodesInRange = range => {
|
|
144
|
+
if (range.startIndex === range.endIndex) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
111
147
|
if (range.endIndex - range.startIndex <= 1) {
|
|
112
148
|
return [range.parent.child(range.startIndex)];
|
|
113
149
|
}
|