@atlaskit/editor-plugin-block-menu 5.1.7 → 5.1.8
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 +10 -0
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +5 -4
- package/dist/cjs/editor-commands/transform-node-utils/wrapMixedContentStep.js +141 -0
- package/dist/cjs/ui/block-menu-components.js +29 -24
- package/dist/cjs/ui/suggested-items-renderer.js +62 -0
- package/dist/cjs/ui/utils/suggested-items-rank.js +0 -41
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -4
- package/dist/es2019/editor-commands/transform-node-utils/wrapMixedContentStep.js +135 -0
- package/dist/es2019/ui/block-menu-components.js +12 -9
- package/dist/es2019/ui/suggested-items-renderer.js +48 -0
- package/dist/es2019/ui/utils/suggested-items-rank.js +17 -110
- package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -4
- package/dist/esm/editor-commands/transform-node-utils/wrapMixedContentStep.js +135 -0
- package/dist/esm/ui/block-menu-components.js +30 -25
- package/dist/esm/ui/suggested-items-renderer.js +54 -0
- package/dist/esm/ui/utils/suggested-items-rank.js +0 -41
- package/dist/types/editor-commands/transform-node-utils/wrapMixedContentStep.d.ts +20 -0
- package/dist/types/ui/suggested-items-renderer.d.ts +8 -0
- package/dist/types/ui/utils/suggested-items-rank.d.ts +0 -36
- package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapMixedContentStep.d.ts +20 -0
- package/dist/types-ts4.5/ui/suggested-items-renderer.d.ts +8 -0
- package/dist/types-ts4.5/ui/utils/suggested-items-rank.d.ts +0 -36
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.1.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1ce87340b7e3e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1ce87340b7e3e) -
|
|
8
|
+
[ux] Implement wrapMixedContentStep function to handle complex container transformations
|
|
9
|
+
- [`4e0c1ce981b5e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4e0c1ce981b5e) -
|
|
10
|
+
EDITOR-2930: Add SuggestedItemsRenderer for suggested block menu section
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 5.1.7
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -14,6 +14,7 @@ var _unwrapExpandStep = require("./unwrapExpandStep");
|
|
|
14
14
|
var _unwrapListStep = require("./unwrapListStep");
|
|
15
15
|
var _unwrapStep = require("./unwrapStep");
|
|
16
16
|
var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
|
|
17
|
+
var _wrapMixedContentStep = require("./wrapMixedContentStep");
|
|
17
18
|
var _wrapStep = require("./wrapStep");
|
|
18
19
|
// Exampled step for overrides:
|
|
19
20
|
// - open Block menu on a paragraph, click 'Panel' in the Turn into'
|
|
@@ -62,15 +63,15 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
62
63
|
codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
|
|
63
64
|
},
|
|
64
65
|
expand: {
|
|
65
|
-
panel: [_unwrapExpandStep.unwrapExpandStep,
|
|
66
|
-
blockquote: [_unwrapExpandStep.unwrapExpandStep,
|
|
66
|
+
panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
67
|
+
blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
67
68
|
layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
68
69
|
paragraph: [_unwrapExpandStep.unwrapExpandStep],
|
|
69
70
|
codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
|
|
70
71
|
},
|
|
71
72
|
nestedExpand: {
|
|
72
|
-
panel: [_unwrapExpandStep.unwrapExpandStep,
|
|
73
|
-
blockquote: [_unwrapExpandStep.unwrapExpandStep,
|
|
73
|
+
panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
74
|
+
blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
74
75
|
paragraph: [_unwrapExpandStep.unwrapExpandStep],
|
|
75
76
|
codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
|
|
76
77
|
},
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.wrapMixedContentStep = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
10
|
+
var _types = require("./types");
|
|
11
|
+
var _unwrapStep = require("./unwrapStep");
|
|
12
|
+
/**
|
|
13
|
+
* Determines if a node can be flattened (unwrapped and its contents merged).
|
|
14
|
+
*
|
|
15
|
+
* According to the text transformations list, flattenable nodes are:
|
|
16
|
+
* - Bulleted list, Numbered list, Task list
|
|
17
|
+
* - Text nodes (heading, paragraph)
|
|
18
|
+
*
|
|
19
|
+
* Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
|
|
20
|
+
*/
|
|
21
|
+
var canFlatten = function canFlatten(node) {
|
|
22
|
+
var category = _types.NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
23
|
+
// Text and list nodes can be flattened (converted to simpler forms)
|
|
24
|
+
return category === 'text' || category === 'list';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Flattens a node by extracting its contents using the appropriate unwrap step.
|
|
29
|
+
* This is only called for text and list nodes that can be converted to simpler forms.
|
|
30
|
+
* Uses unwrapStep to extract children from list containers.
|
|
31
|
+
*/
|
|
32
|
+
var flattenNode = function flattenNode(node, context) {
|
|
33
|
+
return (0, _unwrapStep.unwrapStep)([node], context);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Determines if a node can be wrapped in the target container type.
|
|
38
|
+
* Uses the schema's validContent to check if the target container can hold this node.
|
|
39
|
+
*
|
|
40
|
+
* Note: What can be wrapped depends on the target container type - for example:
|
|
41
|
+
* - Tables and media CAN go inside expand nodes
|
|
42
|
+
* - Tables CANNOT go inside panels or blockquotes
|
|
43
|
+
*/
|
|
44
|
+
var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeTypeName) {
|
|
45
|
+
// Same-type containers should break out as separate containers
|
|
46
|
+
if (node.type.name === targetNodeTypeName) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Use the schema to determine if this node can be contained in the target
|
|
51
|
+
try {
|
|
52
|
+
return targetNodeType.validContent(_model.Fragment.from(node));
|
|
53
|
+
} catch (_unused) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Converts a nestedExpand to a regular expand node.
|
|
60
|
+
* NestedExpands can only exist inside expands, so when breaking out they must be converted.
|
|
61
|
+
*/
|
|
62
|
+
var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
|
|
63
|
+
var _node$attrs;
|
|
64
|
+
var expandType = schema.nodes.expand;
|
|
65
|
+
if (!expandType) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return expandType.createAndFill({
|
|
69
|
+
title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
|
|
70
|
+
}, node.content);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A wrap step that handles mixed content according to the Compatibility Matrix:
|
|
75
|
+
* - Wraps consecutive compatible nodes into the target container
|
|
76
|
+
* - Same-type containers break out as separate containers (preserved as-is)
|
|
77
|
+
* - NestedExpands break out as regular expands (converted since nestedExpand can't exist outside expand)
|
|
78
|
+
* - Container structures that can't be nested in target break out (not flattened)
|
|
79
|
+
* - Text/list nodes that can't be wrapped are flattened and merged into the container
|
|
80
|
+
* - Atomic nodes (tables, media, macros) break out
|
|
81
|
+
*
|
|
82
|
+
* What can be wrapped depends on the target container's schema:
|
|
83
|
+
* - expand → panel: tables break out, nestedExpands convert to expands and break out
|
|
84
|
+
* - expand → blockquote: tables/media break out, nestedExpands convert to expands and break out
|
|
85
|
+
* - expand → expand: tables/media stay inside (expands can contain them)
|
|
86
|
+
*
|
|
87
|
+
* Example: expand(p('a'), table(), p('b')) → panel: [panel(p('a')), table(), panel(p('b'))]
|
|
88
|
+
* Example: expand(p('a'), panel(p('x')), p('b')) → panel: [panel(p('a')), panel(p('x')), panel(p('b'))]
|
|
89
|
+
* Example: expand(p('a'), nestedExpand({title: 'inner'})(p('x')), p('b')) → panel: [panel(p('a')), expand({title: 'inner'})(p('x')), panel(p('b'))]
|
|
90
|
+
*/
|
|
91
|
+
var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedContentStep(nodes, context) {
|
|
92
|
+
var schema = context.schema,
|
|
93
|
+
targetNodeTypeName = context.targetNodeTypeName;
|
|
94
|
+
var targetNodeType = schema.nodes[targetNodeTypeName];
|
|
95
|
+
if (!targetNodeType) {
|
|
96
|
+
return nodes;
|
|
97
|
+
}
|
|
98
|
+
var result = [];
|
|
99
|
+
var currentContainerContent = [];
|
|
100
|
+
var flushCurrentContainer = function flushCurrentContainer() {
|
|
101
|
+
if (currentContainerContent.length > 0) {
|
|
102
|
+
var containerNode = targetNodeType.createAndFill({}, _model.Fragment.fromArray(currentContainerContent));
|
|
103
|
+
if (containerNode) {
|
|
104
|
+
result.push(containerNode);
|
|
105
|
+
}
|
|
106
|
+
currentContainerContent = [];
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
nodes.forEach(function (node) {
|
|
110
|
+
if (canWrapInTarget(node, targetNodeType, targetNodeTypeName)) {
|
|
111
|
+
// Node can be wrapped - add to current container content
|
|
112
|
+
currentContainerContent.push(node);
|
|
113
|
+
} else if (node.type.name === targetNodeTypeName) {
|
|
114
|
+
// Same-type container - breaks out as a separate container (preserved as-is)
|
|
115
|
+
// This handles: "If there's a panel in the expand, it breaks out into a separate panel"
|
|
116
|
+
flushCurrentContainer();
|
|
117
|
+
result.push(node);
|
|
118
|
+
} else if (node.type.name === 'nestedExpand') {
|
|
119
|
+
// NestedExpand can't be wrapped and can't exist outside an expand
|
|
120
|
+
// Convert to regular expand and break out
|
|
121
|
+
flushCurrentContainer();
|
|
122
|
+
var expandNode = convertNestedExpandToExpand(node, schema);
|
|
123
|
+
if (expandNode) {
|
|
124
|
+
result.push(expandNode);
|
|
125
|
+
}
|
|
126
|
+
} else if (canFlatten(node)) {
|
|
127
|
+
var _currentContainerCont;
|
|
128
|
+
// Node cannot be wrapped but CAN be flattened - flatten and add to container
|
|
129
|
+
var flattenedNodes = flattenNode(node, context);
|
|
130
|
+
(_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)(flattenedNodes));
|
|
131
|
+
} else {
|
|
132
|
+
// Node cannot be wrapped AND cannot be flattened (containers, tables, media, macros) - break out
|
|
133
|
+
flushCurrentContainer();
|
|
134
|
+
result.push(node);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Flush any remaining content into a container
|
|
139
|
+
flushCurrentContainer();
|
|
140
|
+
return result.length > 0 ? result : nodes;
|
|
141
|
+
};
|
|
@@ -17,6 +17,7 @@ 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 _suggestedItemsRenderer = require("./suggested-items-renderer");
|
|
20
21
|
var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
|
|
21
22
|
return [{
|
|
22
23
|
type: 'block-menu-item',
|
|
@@ -73,13 +74,17 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
73
74
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION.key]
|
|
74
75
|
},
|
|
75
76
|
component: function component() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement(_suggestedItemsRenderer.SuggestedItemsRenderer, {
|
|
78
|
+
api: api
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
type: 'block-menu-item',
|
|
83
|
+
key: _blockMenu.TRANSFORM_SUGGESTED_MENU_ITEM.key,
|
|
84
|
+
parent: {
|
|
85
|
+
type: 'block-menu-section',
|
|
86
|
+
key: _blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION.key,
|
|
87
|
+
rank: _blockMenu.TRANSFORM_SUGGESTED_MENU_SECTION_RANK[_blockMenu.TRANSFORM_SUGGESTED_MENU_ITEM.key]
|
|
83
88
|
}
|
|
84
89
|
}, {
|
|
85
90
|
type: 'block-menu-section',
|
|
@@ -90,10 +95,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
90
95
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_CREATE_MENU_SECTION.key]
|
|
91
96
|
},
|
|
92
97
|
component: function component() {
|
|
93
|
-
var
|
|
98
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
94
99
|
children: null
|
|
95
100
|
},
|
|
96
|
-
children =
|
|
101
|
+
children = _ref2.children;
|
|
97
102
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
98
103
|
title: "Create"
|
|
99
104
|
}, children);
|
|
@@ -107,10 +112,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
107
112
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key]
|
|
108
113
|
},
|
|
109
114
|
component: function component() {
|
|
110
|
-
var
|
|
115
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
111
116
|
children: null
|
|
112
117
|
},
|
|
113
|
-
children =
|
|
118
|
+
children = _ref3.children;
|
|
114
119
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
115
120
|
title: "Structure"
|
|
116
121
|
}, children);
|
|
@@ -124,10 +129,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
124
129
|
rank: _blockMenu.TRANSFORM_MENU_ITEM_RANK[_blockMenu.TRANSFORM_HEADINGS_MENU_SECTION.key]
|
|
125
130
|
},
|
|
126
131
|
component: function component() {
|
|
127
|
-
var
|
|
132
|
+
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
128
133
|
children: null
|
|
129
134
|
},
|
|
130
|
-
children =
|
|
135
|
+
children = _ref4.children;
|
|
131
136
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
132
137
|
title: "Headings",
|
|
133
138
|
hasSeparator: true
|
|
@@ -137,23 +142,23 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
137
142
|
type: 'block-menu-section',
|
|
138
143
|
key: _blockMenu.TRANSFORM_MENU_SECTION.key,
|
|
139
144
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.TRANSFORM_MENU_SECTION.key],
|
|
140
|
-
component: function component(
|
|
141
|
-
var children =
|
|
145
|
+
component: function component(_ref5) {
|
|
146
|
+
var children = _ref5.children;
|
|
142
147
|
return /*#__PURE__*/_react.default.createElement(_formatMenuSection.FormatMenuSection, {
|
|
143
148
|
api: api
|
|
144
149
|
}, children);
|
|
145
150
|
}
|
|
146
151
|
}];
|
|
147
152
|
};
|
|
148
|
-
var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(
|
|
149
|
-
var api =
|
|
150
|
-
config =
|
|
153
|
+
var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockMenuComponents(_ref6) {
|
|
154
|
+
var api = _ref6.api,
|
|
155
|
+
config = _ref6.config;
|
|
151
156
|
return [].concat((0, _toConsumableArray2.default)(getTurnIntoMenuComponents(api)), [{
|
|
152
157
|
type: 'block-menu-section',
|
|
153
158
|
key: _blockMenu.BLOCK_ACTIONS_MENU_SECTION.key,
|
|
154
159
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.BLOCK_ACTIONS_MENU_SECTION.key],
|
|
155
|
-
component: function component(
|
|
156
|
-
var children =
|
|
160
|
+
component: function component(_ref7) {
|
|
161
|
+
var children = _ref7.children;
|
|
157
162
|
return /*#__PURE__*/_react.default.createElement(_copySection.CopySection, {
|
|
158
163
|
api: api
|
|
159
164
|
}, children);
|
|
@@ -176,8 +181,8 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
|
|
|
176
181
|
type: 'block-menu-section',
|
|
177
182
|
key: _blockMenu.POSITION_MENU_SECTION.key,
|
|
178
183
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.POSITION_MENU_SECTION.key],
|
|
179
|
-
component: function component(
|
|
180
|
-
var children =
|
|
184
|
+
component: function component(_ref8) {
|
|
185
|
+
var children = _ref8.children;
|
|
181
186
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
182
187
|
hasSeparator: true
|
|
183
188
|
}, children);
|
|
@@ -186,8 +191,8 @@ var getBlockMenuComponents = exports.getBlockMenuComponents = function getBlockM
|
|
|
186
191
|
type: 'block-menu-section',
|
|
187
192
|
key: _blockMenu.DELETE_MENU_SECTION.key,
|
|
188
193
|
rank: _blockMenu.MAIN_BLOCK_MENU_SECTION_RANK[_blockMenu.DELETE_MENU_SECTION.key],
|
|
189
|
-
component: function component(
|
|
190
|
-
var children =
|
|
194
|
+
component: function component(_ref9) {
|
|
195
|
+
var children = _ref9.children;
|
|
191
196
|
return /*#__PURE__*/_react.default.createElement(_deleteSection.DeleteSection, {
|
|
192
197
|
api: api
|
|
193
198
|
}, children);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SuggestedItemsRenderer = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
10
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
11
|
+
var _utils = require("../editor-commands/transform-node-utils/utils");
|
|
12
|
+
var _suggestedItemsRank = require("./utils/suggested-items-rank");
|
|
13
|
+
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); }
|
|
14
|
+
var SuggestedItemsRenderer = exports.SuggestedItemsRenderer = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
15
|
+
var _api$blockMenu;
|
|
16
|
+
var api = _ref.api;
|
|
17
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
18
|
+
var _states$blockControls;
|
|
19
|
+
return {
|
|
20
|
+
preservedSelection: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.preservedSelection
|
|
21
|
+
};
|
|
22
|
+
}),
|
|
23
|
+
preservedSelection = _useSharedPluginState.preservedSelection;
|
|
24
|
+
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
25
|
+
var menuItemsMap = (0, _react.useMemo)(function () {
|
|
26
|
+
if (!blockMenuComponents) {
|
|
27
|
+
return new Map();
|
|
28
|
+
}
|
|
29
|
+
return new Map(blockMenuComponents.filter(function (c) {
|
|
30
|
+
return c.type === 'block-menu-item';
|
|
31
|
+
}).map(function (item) {
|
|
32
|
+
return [item.key, item];
|
|
33
|
+
}));
|
|
34
|
+
}, [blockMenuComponents]);
|
|
35
|
+
var suggestedItems = (0, _react.useMemo)(function () {
|
|
36
|
+
if (!preservedSelection || menuItemsMap.size === 0) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
var selectedNode = (0, _utils.getSelectedNode)(preservedSelection);
|
|
40
|
+
if (!selectedNode) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
var nodeTypeName = selectedNode.node.type.name;
|
|
44
|
+
var sortedKeys = (0, _suggestedItemsRank.getSortedSuggestedItems)(nodeTypeName);
|
|
45
|
+
return sortedKeys.map(function (key) {
|
|
46
|
+
return menuItemsMap.get(key);
|
|
47
|
+
}).filter(function (item) {
|
|
48
|
+
return item !== undefined;
|
|
49
|
+
});
|
|
50
|
+
}, [menuItemsMap, preservedSelection]);
|
|
51
|
+
if (suggestedItems.length === 0) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
55
|
+
title: "Suggested"
|
|
56
|
+
}, suggestedItems.map(function (item) {
|
|
57
|
+
var ItemComponent = item.component;
|
|
58
|
+
return ItemComponent ? /*#__PURE__*/_react.default.createElement(ItemComponent, {
|
|
59
|
+
key: item.key
|
|
60
|
+
}) : null;
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
@@ -24,22 +24,6 @@ var _TRANSFORM_SUGGESTED_;
|
|
|
24
24
|
* }
|
|
25
25
|
* }
|
|
26
26
|
*/
|
|
27
|
-
/**
|
|
28
|
-
* Node type keys that map to ProseMirror node types from the ADF schema.
|
|
29
|
-
* These values must match the NodeTypeName type.
|
|
30
|
-
*
|
|
31
|
-
* TypeScript will enforce that all values are valid NodeTypeName values.
|
|
32
|
-
* If a new node type is added, it must be added to NodeTypeName first.
|
|
33
|
-
*
|
|
34
|
-
* Reference: packages/editor/editor-plugin-block-menu/src/editor-commands/transform-node-utils/types.ts
|
|
35
|
-
*
|
|
36
|
-
* Note: 'heading' represents all heading levels (1-6) as a single node type.
|
|
37
|
-
* The specific level is determined by the node's `attrs.level` property at runtime.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* // Usage:
|
|
41
|
-
* const nodeType = BLOCK_MENU_NODE_TYPES.PARAGRAPH; // Type: "paragraph"
|
|
42
|
-
*/
|
|
43
27
|
var BLOCK_MENU_NODE_TYPES = exports.BLOCK_MENU_NODE_TYPES = {
|
|
44
28
|
PARAGRAPH: 'paragraph',
|
|
45
29
|
EXPAND: 'expand',
|
|
@@ -59,35 +43,10 @@ var BLOCK_MENU_NODE_TYPES = exports.BLOCK_MENU_NODE_TYPES = {
|
|
|
59
43
|
EMBED_CARD: 'embedCard',
|
|
60
44
|
TABLE: 'table'
|
|
61
45
|
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Type for node type values extracted from BLOCK_MENU_NODE_TYPES
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Type for the suggested items rank mapping
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Mapping of source node types to suggested transformation menu items with their ranks.
|
|
73
|
-
* Lower rank number = higher priority in the suggested menu section.
|
|
74
|
-
*/
|
|
75
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_H2_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_HEADINGS_H3_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.EXPAND, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_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_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_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_HEADINGS_H2_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.PANEL, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_CODE_BLOCK_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_LAYOUT_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PANEL_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_PARAGRAPH_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_TASK_LIST_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_PARAGRAPH_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.ORDERED_LIST, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_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_HEADINGS_H2_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 300)), (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.TASK_LIST, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_CODE_BLOCK_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_LAYOUT_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.EXTENSION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.BODIED_EXTENSION, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 200), _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 300)), BLOCK_MENU_NODE_TYPES.BLOCK_CARD, (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 200)), BLOCK_MENU_NODE_TYPES.EMBED_CARD, (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key, 200)), BLOCK_MENU_NODE_TYPES.TABLE, (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _blockMenu.TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key, 100), _blockMenu.TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key, 200)));
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get suggested menu items for a given node type
|
|
79
|
-
* @param nodeType - The source node type (e.g., 'paragraph', 'heading')
|
|
80
|
-
* @returns Object mapping menu item keys to their ranks, or undefined if no suggestions
|
|
81
|
-
*/
|
|
82
47
|
var getSuggestedItemsForNodeType = exports.getSuggestedItemsForNodeType = function getSuggestedItemsForNodeType(nodeType) {
|
|
83
48
|
return TRANSFORM_SUGGESTED_ITEMS_RANK[nodeType];
|
|
84
49
|
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get sorted suggested menu item keys for a given node type
|
|
88
|
-
* @param nodeType - The source node type
|
|
89
|
-
* @returns Array of menu item keys sorted by rank (highest priority first)
|
|
90
|
-
*/
|
|
91
50
|
var getSortedSuggestedItems = exports.getSortedSuggestedItems = function getSortedSuggestedItems(nodeType) {
|
|
92
51
|
var suggestions = getSuggestedItemsForNodeType(nodeType);
|
|
93
52
|
if (!suggestions) {
|
|
@@ -8,6 +8,7 @@ import { unwrapExpandStep } from './unwrapExpandStep';
|
|
|
8
8
|
import { unwrapListStep } from './unwrapListStep';
|
|
9
9
|
import { unwrapStep } from './unwrapStep';
|
|
10
10
|
import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
|
|
11
|
+
import { wrapMixedContentStep } from './wrapMixedContentStep';
|
|
11
12
|
import { wrapStep } from './wrapStep';
|
|
12
13
|
|
|
13
14
|
// Exampled step for overrides:
|
|
@@ -57,15 +58,15 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
57
58
|
codeBlock: [unwrapStep, flattenStep, wrapStep]
|
|
58
59
|
},
|
|
59
60
|
expand: {
|
|
60
|
-
panel: [unwrapExpandStep,
|
|
61
|
-
blockquote: [unwrapExpandStep,
|
|
61
|
+
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
62
|
+
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
62
63
|
layoutSection: [unwrapExpandStep, wrapIntoLayoutStep],
|
|
63
64
|
paragraph: [unwrapExpandStep],
|
|
64
65
|
codeBlock: [unwrapExpandStep, flattenStep, wrapStep]
|
|
65
66
|
},
|
|
66
67
|
nestedExpand: {
|
|
67
|
-
panel: [unwrapExpandStep,
|
|
68
|
-
blockquote: [unwrapExpandStep,
|
|
68
|
+
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
69
|
+
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
69
70
|
paragraph: [unwrapExpandStep],
|
|
70
71
|
codeBlock: [unwrapExpandStep, flattenStep, wrapStep]
|
|
71
72
|
},
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { NODE_CATEGORY_BY_TYPE } from './types';
|
|
3
|
+
import { unwrapStep } from './unwrapStep';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Determines if a node can be flattened (unwrapped and its contents merged).
|
|
7
|
+
*
|
|
8
|
+
* According to the text transformations list, flattenable nodes are:
|
|
9
|
+
* - Bulleted list, Numbered list, Task list
|
|
10
|
+
* - Text nodes (heading, paragraph)
|
|
11
|
+
*
|
|
12
|
+
* Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
|
|
13
|
+
*/
|
|
14
|
+
const canFlatten = node => {
|
|
15
|
+
const category = NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
16
|
+
// Text and list nodes can be flattened (converted to simpler forms)
|
|
17
|
+
return category === 'text' || category === 'list';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Flattens a node by extracting its contents using the appropriate unwrap step.
|
|
22
|
+
* This is only called for text and list nodes that can be converted to simpler forms.
|
|
23
|
+
* Uses unwrapStep to extract children from list containers.
|
|
24
|
+
*/
|
|
25
|
+
const flattenNode = (node, context) => {
|
|
26
|
+
return unwrapStep([node], context);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Determines if a node can be wrapped in the target container type.
|
|
31
|
+
* Uses the schema's validContent to check if the target container can hold this node.
|
|
32
|
+
*
|
|
33
|
+
* Note: What can be wrapped depends on the target container type - for example:
|
|
34
|
+
* - Tables and media CAN go inside expand nodes
|
|
35
|
+
* - Tables CANNOT go inside panels or blockquotes
|
|
36
|
+
*/
|
|
37
|
+
const canWrapInTarget = (node, targetNodeType, targetNodeTypeName) => {
|
|
38
|
+
// Same-type containers should break out as separate containers
|
|
39
|
+
if (node.type.name === targetNodeTypeName) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Use the schema to determine if this node can be contained in the target
|
|
44
|
+
try {
|
|
45
|
+
return targetNodeType.validContent(Fragment.from(node));
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
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
|
+
const convertNestedExpandToExpand = (node, schema) => {
|
|
56
|
+
var _node$attrs;
|
|
57
|
+
const 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
|
+
/**
|
|
67
|
+
* A wrap step that handles mixed content according to the Compatibility Matrix:
|
|
68
|
+
* - Wraps consecutive compatible nodes into the target container
|
|
69
|
+
* - Same-type containers break out as separate containers (preserved as-is)
|
|
70
|
+
* - NestedExpands break out as regular expands (converted since nestedExpand can't exist outside expand)
|
|
71
|
+
* - Container structures that can't be nested in target break out (not flattened)
|
|
72
|
+
* - Text/list nodes that can't be wrapped are flattened and merged into the container
|
|
73
|
+
* - Atomic nodes (tables, media, macros) break out
|
|
74
|
+
*
|
|
75
|
+
* What can be wrapped depends on the target container's schema:
|
|
76
|
+
* - expand → panel: tables break out, nestedExpands convert to expands and break out
|
|
77
|
+
* - expand → blockquote: tables/media break out, nestedExpands convert to expands and break out
|
|
78
|
+
* - expand → expand: tables/media stay inside (expands can contain them)
|
|
79
|
+
*
|
|
80
|
+
* Example: expand(p('a'), table(), p('b')) → panel: [panel(p('a')), table(), panel(p('b'))]
|
|
81
|
+
* Example: expand(p('a'), panel(p('x')), p('b')) → panel: [panel(p('a')), panel(p('x')), panel(p('b'))]
|
|
82
|
+
* Example: expand(p('a'), nestedExpand({title: 'inner'})(p('x')), p('b')) → panel: [panel(p('a')), expand({title: 'inner'})(p('x')), panel(p('b'))]
|
|
83
|
+
*/
|
|
84
|
+
export const wrapMixedContentStep = (nodes, context) => {
|
|
85
|
+
const {
|
|
86
|
+
schema,
|
|
87
|
+
targetNodeTypeName
|
|
88
|
+
} = context;
|
|
89
|
+
const targetNodeType = schema.nodes[targetNodeTypeName];
|
|
90
|
+
if (!targetNodeType) {
|
|
91
|
+
return nodes;
|
|
92
|
+
}
|
|
93
|
+
const result = [];
|
|
94
|
+
let currentContainerContent = [];
|
|
95
|
+
const flushCurrentContainer = () => {
|
|
96
|
+
if (currentContainerContent.length > 0) {
|
|
97
|
+
const containerNode = targetNodeType.createAndFill({}, Fragment.fromArray(currentContainerContent));
|
|
98
|
+
if (containerNode) {
|
|
99
|
+
result.push(containerNode);
|
|
100
|
+
}
|
|
101
|
+
currentContainerContent = [];
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
nodes.forEach(node => {
|
|
105
|
+
if (canWrapInTarget(node, targetNodeType, targetNodeTypeName)) {
|
|
106
|
+
// Node can be wrapped - add to current container content
|
|
107
|
+
currentContainerContent.push(node);
|
|
108
|
+
} else if (node.type.name === targetNodeTypeName) {
|
|
109
|
+
// Same-type container - breaks out as a separate container (preserved as-is)
|
|
110
|
+
// This handles: "If there's a panel in the expand, it breaks out into a separate panel"
|
|
111
|
+
flushCurrentContainer();
|
|
112
|
+
result.push(node);
|
|
113
|
+
} else if (node.type.name === 'nestedExpand') {
|
|
114
|
+
// NestedExpand can't be wrapped and can't exist outside an expand
|
|
115
|
+
// Convert to regular expand and break out
|
|
116
|
+
flushCurrentContainer();
|
|
117
|
+
const expandNode = convertNestedExpandToExpand(node, schema);
|
|
118
|
+
if (expandNode) {
|
|
119
|
+
result.push(expandNode);
|
|
120
|
+
}
|
|
121
|
+
} else if (canFlatten(node)) {
|
|
122
|
+
// Node cannot be wrapped but CAN be flattened - flatten and add to container
|
|
123
|
+
const flattenedNodes = flattenNode(node, context);
|
|
124
|
+
currentContainerContent.push(...flattenedNodes);
|
|
125
|
+
} else {
|
|
126
|
+
// Node cannot be wrapped AND cannot be flattened (containers, tables, media, macros) - break out
|
|
127
|
+
flushCurrentContainer();
|
|
128
|
+
result.push(node);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Flush any remaining content into a container
|
|
133
|
+
flushCurrentContainer();
|
|
134
|
+
return result.length > 0 ? result : nodes;
|
|
135
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { BLOCK_ACTIONS_COPY_LINK_TO_BLOCK_MENU_ITEM, BLOCK_ACTIONS_MENU_SECTION, BLOCK_ACTIONS_MENU_SECTION_RANK, DELETE_MENU_SECTION, DELETE_MENU_SECTION_RANK, DELETE_MENU_ITEM, POSITION_MENU_SECTION, POSITION_MENU_SECTION_RANK, POSITION_MOVE_DOWN_MENU_ITEM, POSITION_MOVE_UP_MENU_ITEM, TRANSFORM_MENU_ITEM, TRANSFORM_MENU_ITEM_RANK, TRANSFORM_MENU_SECTION, TRANSFORM_MENU_SECTION_RANK, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_SUGGESTED_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_HEADINGS_MENU_SECTION, MAIN_BLOCK_MENU_SECTION_RANK } from '@atlaskit/editor-common/block-menu';
|
|
2
|
+
import { BLOCK_ACTIONS_COPY_LINK_TO_BLOCK_MENU_ITEM, BLOCK_ACTIONS_MENU_SECTION, BLOCK_ACTIONS_MENU_SECTION_RANK, DELETE_MENU_SECTION, DELETE_MENU_SECTION_RANK, DELETE_MENU_ITEM, POSITION_MENU_SECTION, POSITION_MENU_SECTION_RANK, POSITION_MOVE_DOWN_MENU_ITEM, POSITION_MOVE_UP_MENU_ITEM, TRANSFORM_MENU_ITEM, TRANSFORM_MENU_ITEM_RANK, TRANSFORM_MENU_SECTION, TRANSFORM_MENU_SECTION_RANK, TRANSFORM_CREATE_MENU_SECTION, TRANSFORM_SUGGESTED_MENU_SECTION, TRANSFORM_STRUCTURE_MENU_SECTION, TRANSFORM_HEADINGS_MENU_SECTION, MAIN_BLOCK_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_SECTION_RANK, TRANSFORM_SUGGESTED_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
|
|
3
3
|
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
4
4
|
import { CopyLinkDropdownItem } from './copy-link';
|
|
5
5
|
import { CopySection } from './copy-section';
|
|
@@ -9,6 +9,7 @@ import { FormatMenuComponent } from './format-menu-nested';
|
|
|
9
9
|
import { FormatMenuSection } from './format-menu-section';
|
|
10
10
|
import { MoveDownDropdownItem } from './move-down';
|
|
11
11
|
import { MoveUpDropdownItem } from './move-up';
|
|
12
|
+
import { SuggestedItemsRenderer } from './suggested-items-renderer';
|
|
12
13
|
const getMoveUpMoveDownMenuComponents = api => {
|
|
13
14
|
return [{
|
|
14
15
|
type: 'block-menu-item',
|
|
@@ -60,14 +61,16 @@ const getTurnIntoMenuComponents = api => {
|
|
|
60
61
|
key: TRANSFORM_MENU_ITEM.key,
|
|
61
62
|
rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_SUGGESTED_MENU_SECTION.key]
|
|
62
63
|
},
|
|
63
|
-
component: ({
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
component: () => /*#__PURE__*/React.createElement(SuggestedItemsRenderer, {
|
|
65
|
+
api: api
|
|
66
|
+
})
|
|
67
|
+
}, {
|
|
68
|
+
type: 'block-menu-item',
|
|
69
|
+
key: TRANSFORM_SUGGESTED_MENU_ITEM.key,
|
|
70
|
+
parent: {
|
|
71
|
+
type: 'block-menu-section',
|
|
72
|
+
key: TRANSFORM_SUGGESTED_MENU_SECTION.key,
|
|
73
|
+
rank: TRANSFORM_SUGGESTED_MENU_SECTION_RANK[TRANSFORM_SUGGESTED_MENU_ITEM.key]
|
|
71
74
|
}
|
|
72
75
|
}, {
|
|
73
76
|
type: 'block-menu-section',
|