@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.
Files changed (23) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/transform.js +5 -4
  3. package/dist/cjs/editor-commands/transform-node-utils/wrapMixedContentStep.js +141 -0
  4. package/dist/cjs/ui/block-menu-components.js +29 -24
  5. package/dist/cjs/ui/suggested-items-renderer.js +62 -0
  6. package/dist/cjs/ui/utils/suggested-items-rank.js +0 -41
  7. package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -4
  8. package/dist/es2019/editor-commands/transform-node-utils/wrapMixedContentStep.js +135 -0
  9. package/dist/es2019/ui/block-menu-components.js +12 -9
  10. package/dist/es2019/ui/suggested-items-renderer.js +48 -0
  11. package/dist/es2019/ui/utils/suggested-items-rank.js +17 -110
  12. package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -4
  13. package/dist/esm/editor-commands/transform-node-utils/wrapMixedContentStep.js +135 -0
  14. package/dist/esm/ui/block-menu-components.js +30 -25
  15. package/dist/esm/ui/suggested-items-renderer.js +54 -0
  16. package/dist/esm/ui/utils/suggested-items-rank.js +0 -41
  17. package/dist/types/editor-commands/transform-node-utils/wrapMixedContentStep.d.ts +20 -0
  18. package/dist/types/ui/suggested-items-renderer.d.ts +8 -0
  19. package/dist/types/ui/utils/suggested-items-rank.d.ts +0 -36
  20. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapMixedContentStep.d.ts +20 -0
  21. package/dist/types-ts4.5/ui/suggested-items-renderer.d.ts +8 -0
  22. package/dist/types-ts4.5/ui/utils/suggested-items-rank.d.ts +0 -36
  23. package/package.json +3 -3
@@ -0,0 +1,48 @@
1
+ import React, { useMemo } from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
4
+ import { getSelectedNode } from '../editor-commands/transform-node-utils/utils';
5
+ import { getSortedSuggestedItems } from './utils/suggested-items-rank';
6
+ export const SuggestedItemsRenderer = /*#__PURE__*/React.memo(({
7
+ api
8
+ }) => {
9
+ var _api$blockMenu;
10
+ const {
11
+ preservedSelection
12
+ } = useSharedPluginStateWithSelector(api, ['blockControls'], states => {
13
+ var _states$blockControls;
14
+ return {
15
+ preservedSelection: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.preservedSelection
16
+ };
17
+ });
18
+ const blockMenuComponents = api === null || api === void 0 ? void 0 : (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
19
+ const menuItemsMap = useMemo(() => {
20
+ if (!blockMenuComponents) {
21
+ return new Map();
22
+ }
23
+ return new Map(blockMenuComponents.filter(c => c.type === 'block-menu-item').map(item => [item.key, item]));
24
+ }, [blockMenuComponents]);
25
+ const suggestedItems = useMemo(() => {
26
+ if (!preservedSelection || menuItemsMap.size === 0) {
27
+ return [];
28
+ }
29
+ const selectedNode = getSelectedNode(preservedSelection);
30
+ if (!selectedNode) {
31
+ return [];
32
+ }
33
+ const nodeTypeName = selectedNode.node.type.name;
34
+ const sortedKeys = getSortedSuggestedItems(nodeTypeName);
35
+ return sortedKeys.map(key => menuItemsMap.get(key)).filter(item => item !== undefined);
36
+ }, [menuItemsMap, preservedSelection]);
37
+ if (suggestedItems.length === 0) {
38
+ return null;
39
+ }
40
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
41
+ title: "Suggested"
42
+ }, suggestedItems.map(item => {
43
+ const ItemComponent = item.component;
44
+ return ItemComponent ? /*#__PURE__*/React.createElement(ItemComponent, {
45
+ key: item.key
46
+ }) : null;
47
+ }));
48
+ });
@@ -15,22 +15,6 @@
15
15
  */
16
16
 
17
17
  import { TRANSFORM_STRUCTURE_PANEL_MENU_ITEM, TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM, TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM, TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM, TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM, TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM, TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM, TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM, TRANSFORM_HEADINGS_H2_MENU_ITEM, TRANSFORM_HEADINGS_H3_MENU_ITEM, TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
18
- /**
19
- * Node type keys that map to ProseMirror node types from the ADF schema.
20
- * These values must match the NodeTypeName type.
21
- *
22
- * TypeScript will enforce that all values are valid NodeTypeName values.
23
- * If a new node type is added, it must be added to NodeTypeName first.
24
- *
25
- * Reference: packages/editor/editor-plugin-block-menu/src/editor-commands/transform-node-utils/types.ts
26
- *
27
- * Note: 'heading' represents all heading levels (1-6) as a single node type.
28
- * The specific level is determined by the node's `attrs.level` property at runtime.
29
- *
30
- * @example
31
- * // Usage:
32
- * const nodeType = BLOCK_MENU_NODE_TYPES.PARAGRAPH; // Type: "paragraph"
33
- */
34
18
  export const BLOCK_MENU_NODE_TYPES = {
35
19
  PARAGRAPH: 'paragraph',
36
20
  EXPAND: 'expand',
@@ -50,170 +34,93 @@ export const BLOCK_MENU_NODE_TYPES = {
50
34
  EMBED_CARD: 'embedCard',
51
35
  TABLE: 'table'
52
36
  };
53
-
54
- /**
55
- * Type for node type values extracted from BLOCK_MENU_NODE_TYPES
56
- */
57
-
58
- /**
59
- * Type for the suggested items rank mapping
60
- */
61
-
62
- /**
63
- * Mapping of source node types to suggested transformation menu items with their ranks.
64
- * Lower rank number = higher priority in the suggested menu section.
65
- */
66
37
  export const TRANSFORM_SUGGESTED_ITEMS_RANK = {
67
- // Paragraph suggestions
68
38
  [BLOCK_MENU_NODE_TYPES.PARAGRAPH]: {
69
39
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
70
- // Turn into Panel
71
40
  [TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 200,
72
- // Turn into Heading 2
73
- [TRANSFORM_HEADINGS_H3_MENU_ITEM.key]: 300 // Turn into Heading 3
41
+ [TRANSFORM_HEADINGS_H3_MENU_ITEM.key]: 300
74
42
  },
75
- // Expand suggestions
76
43
  [BLOCK_MENU_NODE_TYPES.EXPAND]: {
77
44
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
78
- // Turn into Panel (wrap content)
79
45
  [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
80
- // Turn into Layout
81
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
46
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300
82
47
  },
83
- // Quote block (blockquote) suggestions
84
48
  [BLOCK_MENU_NODE_TYPES.BLOCKQUOTE]: {
85
49
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
86
- // Turn into Panel
87
50
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
88
- // Turn into Paragraph
89
- [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 300 // Turn into Layout
51
+ [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 300
90
52
  },
91
- // Layout suggestions
92
53
  [BLOCK_MENU_NODE_TYPES.LAYOUT_SECTION]: {
93
54
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
94
- // Wrap layout in panel
95
55
  [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 200,
96
- // Make layout collapsible
97
- [TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 300 // doesn't meet compatibility matrix, needs to be updated
56
+ [TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 300
98
57
  },
99
- // Panel suggestions
100
58
  [BLOCK_MENU_NODE_TYPES.PANEL]: {
101
59
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
102
- // Turn into Paragraph
103
60
  [TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key]: 200,
104
- // Turn into Blockquote
105
- [TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300 // Turn into Code Block
61
+ [TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300
106
62
  },
107
- // Code block suggestions
108
63
  [BLOCK_MENU_NODE_TYPES.CODE_BLOCK]: {
109
64
  [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 100,
110
- // Turn into Expand
111
65
  [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
112
- // Turn into Layout
113
- [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300 // Turn into Panel
66
+ [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300
114
67
  },
115
- // Decision suggestions
116
68
  [BLOCK_MENU_NODE_TYPES.DECISION]: {
117
69
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
118
- // Wrap in Panel (Decision style)
119
70
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
120
- // Turn into Paragraph
121
- [TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]: 300 // Convert to Task List
71
+ [TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]: 300
122
72
  },
123
- // Bulleted list suggestions
124
73
  [BLOCK_MENU_NODE_TYPES.BULLET_LIST]: {
125
74
  [TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key]: 100,
126
- // Turn into Numbered list
127
75
  [TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key]: 200,
128
- // Turn into Blockquote
129
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
76
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300
130
77
  },
131
- // Numbered list (ordered list) suggestions
132
78
  [BLOCK_MENU_NODE_TYPES.ORDERED_LIST]: {
133
79
  [TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key]: 100,
134
- // Turn into Bulleted list
135
80
  [TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]: 200,
136
- // Turn into Task List
137
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
81
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300
138
82
  },
139
- // Heading suggestions
140
- // Note: For headings, the specific heading level would need to be determined at runtime
141
- // This provides a general mapping, but actual implementation should consider current heading level
142
83
  [BLOCK_MENU_NODE_TYPES.HEADING]: {
143
84
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
144
- // Turn into Paragraph
145
85
  [TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 200,
146
- // Turn into Heading 2
147
- [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300 // Wrap in Panel
86
+ [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300
148
87
  },
149
- // Task list suggestions
150
88
  [BLOCK_MENU_NODE_TYPES.TASK_LIST]: {
151
89
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
152
- // Turn into Paragraph
153
90
  [TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key]: 200,
154
- // Turn into Ordered list
155
- [TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300 // Turn into Code Block (for technical TODOs)
91
+ [TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300
156
92
  },
157
- // Media (mediaSingle) suggestions
158
93
  [BLOCK_MENU_NODE_TYPES.MEDIA_SINGLE]: {
159
94
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
160
- // Wrap in Panel
161
95
  [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
162
- // Place into Layout
163
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // doesn't meet compatibility matrix, needs to be updated
96
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300
164
97
  },
165
- // Extension (app/macro) suggestions
166
98
  [BLOCK_MENU_NODE_TYPES.EXTENSION]: {
167
99
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
168
- // Wrap in Panel
169
100
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
170
- // doesn't meet compatibility matrix, needs to be updated
171
- [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300 // Collapse in Expand
101
+ [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300
172
102
  },
173
- // Bodied Extension suggestions (same as Extension)
174
103
  [BLOCK_MENU_NODE_TYPES.BODIED_EXTENSION]: {
175
104
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
176
- // Wrap in Panel
177
105
  [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
178
- // doesn't meet compatibility matrix, needs to be updated
179
- [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300 // Collapse in Expand
106
+ [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300
180
107
  },
181
- // Smart link Card suggestions
182
108
  [BLOCK_MENU_NODE_TYPES.BLOCK_CARD]: {
183
- // Note: Smart link card conversion would be rank 100 (demote to card)
184
109
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
185
- // Wrap in Panel
186
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200 // doesn't meet compatibility matrix, needs to be updated
110
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200
187
111
  },
188
- // Smart link Embed suggestions
189
112
  [BLOCK_MENU_NODE_TYPES.EMBED_CARD]: {
190
- // Note: Smart link embed conversion would be rank 100 (promote to embed)
191
113
  [TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
192
- // Wrap in Panel
193
- [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200 // doesn't meet compatibility matrix, needs to be updated
114
+ [TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200
194
115
  },
195
- // Table suggestions
196
116
  [BLOCK_MENU_NODE_TYPES.TABLE]: {
197
117
  [TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 100,
198
- // Turn into Expand
199
- [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200 // Turn into Layout
118
+ [TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200
200
119
  }
201
120
  };
202
-
203
- /**
204
- * Get suggested menu items for a given node type
205
- * @param nodeType - The source node type (e.g., 'paragraph', 'heading')
206
- * @returns Object mapping menu item keys to their ranks, or undefined if no suggestions
207
- */
208
121
  export const getSuggestedItemsForNodeType = nodeType => {
209
122
  return TRANSFORM_SUGGESTED_ITEMS_RANK[nodeType];
210
123
  };
211
-
212
- /**
213
- * Get sorted suggested menu item keys for a given node type
214
- * @param nodeType - The source node type
215
- * @returns Array of menu item keys sorted by rank (highest priority first)
216
- */
217
124
  export const getSortedSuggestedItems = nodeType => {
218
125
  const suggestions = getSuggestedItemsForNodeType(nodeType);
219
126
  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 @@ var TRANSFORM_STEPS_OVERRIDE = {
57
58
  codeBlock: [unwrapStep, flattenStep, wrapStep]
58
59
  },
59
60
  expand: {
60
- panel: [unwrapExpandStep, wrapStep],
61
- blockquote: [unwrapExpandStep, wrapStep],
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, wrapStep],
68
- blockquote: [unwrapExpandStep, wrapStep],
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 _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
+ import { NODE_CATEGORY_BY_TYPE } from './types';
4
+ import { unwrapStep } from './unwrapStep';
5
+
6
+ /**
7
+ * Determines if a node can be flattened (unwrapped and its contents merged).
8
+ *
9
+ * According to the text transformations list, flattenable nodes are:
10
+ * - Bulleted list, Numbered list, Task list
11
+ * - Text nodes (heading, paragraph)
12
+ *
13
+ * Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
14
+ */
15
+ var canFlatten = function canFlatten(node) {
16
+ var category = NODE_CATEGORY_BY_TYPE[node.type.name];
17
+ // Text and list nodes can be flattened (converted to simpler forms)
18
+ return category === 'text' || category === 'list';
19
+ };
20
+
21
+ /**
22
+ * Flattens a node by extracting its contents using the appropriate unwrap step.
23
+ * This is only called for text and list nodes that can be converted to simpler forms.
24
+ * Uses unwrapStep to extract children from list containers.
25
+ */
26
+ var flattenNode = function flattenNode(node, context) {
27
+ return unwrapStep([node], context);
28
+ };
29
+
30
+ /**
31
+ * Determines if a node can be wrapped in the target container type.
32
+ * Uses the schema's validContent to check if the target container can hold this node.
33
+ *
34
+ * Note: What can be wrapped depends on the target container type - for example:
35
+ * - Tables and media CAN go inside expand nodes
36
+ * - Tables CANNOT go inside panels or blockquotes
37
+ */
38
+ var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeTypeName) {
39
+ // Same-type containers should break out as separate containers
40
+ if (node.type.name === targetNodeTypeName) {
41
+ return false;
42
+ }
43
+
44
+ // Use the schema to determine if this node can be contained in the target
45
+ try {
46
+ return targetNodeType.validContent(Fragment.from(node));
47
+ } catch (_unused) {
48
+ return false;
49
+ }
50
+ };
51
+
52
+ /**
53
+ * Converts a nestedExpand to a regular expand node.
54
+ * NestedExpands can only exist inside expands, so when breaking out they must be converted.
55
+ */
56
+ var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
57
+ var _node$attrs;
58
+ var expandType = schema.nodes.expand;
59
+ if (!expandType) {
60
+ return null;
61
+ }
62
+ return expandType.createAndFill({
63
+ title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
64
+ }, node.content);
65
+ };
66
+
67
+ /**
68
+ * A wrap step that handles mixed content according to the Compatibility Matrix:
69
+ * - Wraps consecutive compatible nodes into the target container
70
+ * - Same-type containers break out as separate containers (preserved as-is)
71
+ * - NestedExpands break out as regular expands (converted since nestedExpand can't exist outside expand)
72
+ * - Container structures that can't be nested in target break out (not flattened)
73
+ * - Text/list nodes that can't be wrapped are flattened and merged into the container
74
+ * - Atomic nodes (tables, media, macros) break out
75
+ *
76
+ * What can be wrapped depends on the target container's schema:
77
+ * - expand → panel: tables break out, nestedExpands convert to expands and break out
78
+ * - expand → blockquote: tables/media break out, nestedExpands convert to expands and break out
79
+ * - expand → expand: tables/media stay inside (expands can contain them)
80
+ *
81
+ * Example: expand(p('a'), table(), p('b')) → panel: [panel(p('a')), table(), panel(p('b'))]
82
+ * Example: expand(p('a'), panel(p('x')), p('b')) → panel: [panel(p('a')), panel(p('x')), panel(p('b'))]
83
+ * Example: expand(p('a'), nestedExpand({title: 'inner'})(p('x')), p('b')) → panel: [panel(p('a')), expand({title: 'inner'})(p('x')), panel(p('b'))]
84
+ */
85
+ export var wrapMixedContentStep = function wrapMixedContentStep(nodes, context) {
86
+ var schema = context.schema,
87
+ targetNodeTypeName = context.targetNodeTypeName;
88
+ var targetNodeType = schema.nodes[targetNodeTypeName];
89
+ if (!targetNodeType) {
90
+ return nodes;
91
+ }
92
+ var result = [];
93
+ var currentContainerContent = [];
94
+ var flushCurrentContainer = function flushCurrentContainer() {
95
+ if (currentContainerContent.length > 0) {
96
+ var containerNode = targetNodeType.createAndFill({}, Fragment.fromArray(currentContainerContent));
97
+ if (containerNode) {
98
+ result.push(containerNode);
99
+ }
100
+ currentContainerContent = [];
101
+ }
102
+ };
103
+ nodes.forEach(function (node) {
104
+ if (canWrapInTarget(node, targetNodeType, targetNodeTypeName)) {
105
+ // Node can be wrapped - add to current container content
106
+ currentContainerContent.push(node);
107
+ } else if (node.type.name === targetNodeTypeName) {
108
+ // Same-type container - breaks out as a separate container (preserved as-is)
109
+ // This handles: "If there's a panel in the expand, it breaks out into a separate panel"
110
+ flushCurrentContainer();
111
+ result.push(node);
112
+ } else if (node.type.name === 'nestedExpand') {
113
+ // NestedExpand can't be wrapped and can't exist outside an expand
114
+ // Convert to regular expand and break out
115
+ flushCurrentContainer();
116
+ var expandNode = convertNestedExpandToExpand(node, schema);
117
+ if (expandNode) {
118
+ result.push(expandNode);
119
+ }
120
+ } else if (canFlatten(node)) {
121
+ var _currentContainerCont;
122
+ // Node cannot be wrapped but CAN be flattened - flatten and add to container
123
+ var flattenedNodes = flattenNode(node, context);
124
+ (_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, _toConsumableArray(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,6 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import React from 'react';
3
- 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';
3
+ 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';
4
4
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
5
5
  import { CopyLinkDropdownItem } from './copy-link';
6
6
  import { CopySection } from './copy-section';
@@ -10,6 +10,7 @@ import { FormatMenuComponent } from './format-menu-nested';
10
10
  import { FormatMenuSection } from './format-menu-section';
11
11
  import { MoveDownDropdownItem } from './move-down';
12
12
  import { MoveUpDropdownItem } from './move-up';
13
+ import { SuggestedItemsRenderer } from './suggested-items-renderer';
13
14
  var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
14
15
  return [{
15
16
  type: 'block-menu-item',
@@ -66,13 +67,17 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
66
67
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_SUGGESTED_MENU_SECTION.key]
67
68
  },
68
69
  component: function component() {
69
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
70
- children: null
71
- },
72
- children = _ref2.children;
73
- return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
74
- title: "Suggested"
75
- }, children);
70
+ return /*#__PURE__*/React.createElement(SuggestedItemsRenderer, {
71
+ api: api
72
+ });
73
+ }
74
+ }, {
75
+ type: 'block-menu-item',
76
+ key: TRANSFORM_SUGGESTED_MENU_ITEM.key,
77
+ parent: {
78
+ type: 'block-menu-section',
79
+ key: TRANSFORM_SUGGESTED_MENU_SECTION.key,
80
+ rank: TRANSFORM_SUGGESTED_MENU_SECTION_RANK[TRANSFORM_SUGGESTED_MENU_ITEM.key]
76
81
  }
77
82
  }, {
78
83
  type: 'block-menu-section',
@@ -83,10 +88,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
83
88
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_CREATE_MENU_SECTION.key]
84
89
  },
85
90
  component: function component() {
86
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
91
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
87
92
  children: null
88
93
  },
89
- children = _ref3.children;
94
+ children = _ref2.children;
90
95
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
91
96
  title: "Create"
92
97
  }, children);
@@ -100,10 +105,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
100
105
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_STRUCTURE_MENU_SECTION.key]
101
106
  },
102
107
  component: function component() {
103
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
108
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
104
109
  children: null
105
110
  },
106
- children = _ref4.children;
111
+ children = _ref3.children;
107
112
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
108
113
  title: "Structure"
109
114
  }, children);
@@ -117,10 +122,10 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
117
122
  rank: TRANSFORM_MENU_ITEM_RANK[TRANSFORM_HEADINGS_MENU_SECTION.key]
118
123
  },
119
124
  component: function component() {
120
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
125
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
121
126
  children: null
122
127
  },
123
- children = _ref5.children;
128
+ children = _ref4.children;
124
129
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
125
130
  title: "Headings",
126
131
  hasSeparator: true
@@ -130,23 +135,23 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
130
135
  type: 'block-menu-section',
131
136
  key: TRANSFORM_MENU_SECTION.key,
132
137
  rank: MAIN_BLOCK_MENU_SECTION_RANK[TRANSFORM_MENU_SECTION.key],
133
- component: function component(_ref6) {
134
- var children = _ref6.children;
138
+ component: function component(_ref5) {
139
+ var children = _ref5.children;
135
140
  return /*#__PURE__*/React.createElement(FormatMenuSection, {
136
141
  api: api
137
142
  }, children);
138
143
  }
139
144
  }];
140
145
  };
141
- export var getBlockMenuComponents = function getBlockMenuComponents(_ref7) {
142
- var api = _ref7.api,
143
- config = _ref7.config;
146
+ export var getBlockMenuComponents = function getBlockMenuComponents(_ref6) {
147
+ var api = _ref6.api,
148
+ config = _ref6.config;
144
149
  return [].concat(_toConsumableArray(getTurnIntoMenuComponents(api)), [{
145
150
  type: 'block-menu-section',
146
151
  key: BLOCK_ACTIONS_MENU_SECTION.key,
147
152
  rank: MAIN_BLOCK_MENU_SECTION_RANK[BLOCK_ACTIONS_MENU_SECTION.key],
148
- component: function component(_ref8) {
149
- var children = _ref8.children;
153
+ component: function component(_ref7) {
154
+ var children = _ref7.children;
150
155
  return /*#__PURE__*/React.createElement(CopySection, {
151
156
  api: api
152
157
  }, children);
@@ -169,8 +174,8 @@ export var getBlockMenuComponents = function getBlockMenuComponents(_ref7) {
169
174
  type: 'block-menu-section',
170
175
  key: POSITION_MENU_SECTION.key,
171
176
  rank: MAIN_BLOCK_MENU_SECTION_RANK[POSITION_MENU_SECTION.key],
172
- component: function component(_ref9) {
173
- var children = _ref9.children;
177
+ component: function component(_ref8) {
178
+ var children = _ref8.children;
174
179
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
175
180
  hasSeparator: true
176
181
  }, children);
@@ -179,8 +184,8 @@ export var getBlockMenuComponents = function getBlockMenuComponents(_ref7) {
179
184
  type: 'block-menu-section',
180
185
  key: DELETE_MENU_SECTION.key,
181
186
  rank: MAIN_BLOCK_MENU_SECTION_RANK[DELETE_MENU_SECTION.key],
182
- component: function component(_ref0) {
183
- var children = _ref0.children;
187
+ component: function component(_ref9) {
188
+ var children = _ref9.children;
184
189
  return /*#__PURE__*/React.createElement(DeleteSection, {
185
190
  api: api
186
191
  }, children);
@@ -0,0 +1,54 @@
1
+ import React, { useMemo } from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
4
+ import { getSelectedNode } from '../editor-commands/transform-node-utils/utils';
5
+ import { getSortedSuggestedItems } from './utils/suggested-items-rank';
6
+ export var SuggestedItemsRenderer = /*#__PURE__*/React.memo(function (_ref) {
7
+ var _api$blockMenu;
8
+ var api = _ref.api;
9
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
10
+ var _states$blockControls;
11
+ return {
12
+ preservedSelection: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.preservedSelection
13
+ };
14
+ }),
15
+ preservedSelection = _useSharedPluginState.preservedSelection;
16
+ var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
17
+ var menuItemsMap = useMemo(function () {
18
+ if (!blockMenuComponents) {
19
+ return new Map();
20
+ }
21
+ return new Map(blockMenuComponents.filter(function (c) {
22
+ return c.type === 'block-menu-item';
23
+ }).map(function (item) {
24
+ return [item.key, item];
25
+ }));
26
+ }, [blockMenuComponents]);
27
+ var suggestedItems = useMemo(function () {
28
+ if (!preservedSelection || menuItemsMap.size === 0) {
29
+ return [];
30
+ }
31
+ var selectedNode = getSelectedNode(preservedSelection);
32
+ if (!selectedNode) {
33
+ return [];
34
+ }
35
+ var nodeTypeName = selectedNode.node.type.name;
36
+ var sortedKeys = getSortedSuggestedItems(nodeTypeName);
37
+ return sortedKeys.map(function (key) {
38
+ return menuItemsMap.get(key);
39
+ }).filter(function (item) {
40
+ return item !== undefined;
41
+ });
42
+ }, [menuItemsMap, preservedSelection]);
43
+ if (suggestedItems.length === 0) {
44
+ return null;
45
+ }
46
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
47
+ title: "Suggested"
48
+ }, suggestedItems.map(function (item) {
49
+ var ItemComponent = item.component;
50
+ return ItemComponent ? /*#__PURE__*/React.createElement(ItemComponent, {
51
+ key: item.key
52
+ }) : null;
53
+ }));
54
+ });