@atlaskit/editor-plugin-block-menu 6.0.9 → 6.0.12
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 +22 -0
- package/dist/cjs/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +224 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +4 -238
- package/dist/cjs/ui/block-menu-components.js +12 -0
- package/dist/cjs/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/cjs/ui/block-menu-renderer/utils.js +4 -7
- package/dist/cjs/ui/hooks/useSuggestedItems.js +4 -37
- package/dist/cjs/ui/utils/createMenuItemsMap.js +19 -0
- package/dist/cjs/ui/utils/getSuggestedItemsFromSelection.js +40 -0
- package/dist/es2019/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +56 -1
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -240
- package/dist/es2019/ui/block-menu-components.js +13 -1
- package/dist/es2019/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/es2019/ui/block-menu-renderer/utils.js +4 -7
- package/dist/es2019/ui/hooks/useSuggestedItems.js +4 -28
- package/dist/es2019/ui/utils/createMenuItemsMap.js +9 -0
- package/dist/es2019/ui/utils/getSuggestedItemsFromSelection.js +30 -0
- package/dist/esm/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
- package/dist/esm/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
- package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -240
- package/dist/esm/ui/block-menu-components.js +12 -0
- package/dist/esm/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/esm/ui/block-menu-renderer/utils.js +4 -7
- package/dist/esm/ui/hooks/useSuggestedItems.js +4 -37
- package/dist/esm/ui/utils/createMenuItemsMap.js +13 -0
- package/dist/esm/ui/utils/getSuggestedItemsFromSelection.js +35 -0
- package/dist/types/blockMenuPluginType.d.ts +1 -0
- package/dist/types/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
- package/dist/types/ui/block-menu-renderer/utils.d.ts +2 -3
- package/dist/types/ui/utils/createMenuItemsMap.d.ts +6 -0
- package/dist/types/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/utils.d.ts +2 -3
- package/dist/types-ts4.5/ui/utils/createMenuItemsMap.d.ts +6 -0
- package/dist/types-ts4.5/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
- package/package.json +6 -6
|
@@ -1,238 +1,6 @@
|
|
|
1
1
|
import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { convertEachNodeStep } from './steps/convertEachNodeStep';
|
|
5
|
-
import { decisionListToListStep } from './steps/decisionListToListStep';
|
|
6
|
-
import { flattenListStep } from './steps/flattenListStep';
|
|
7
|
-
import { listToDecisionListStep } from './steps/listToDecisionListStep';
|
|
8
|
-
import { listToListStep } from './steps/listToListStep';
|
|
9
|
-
import { mergeNeighbourListsStep } from './steps/mergeNeighbourListsStep';
|
|
10
|
-
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
11
|
-
import { unwrapListStep } from './steps/unwrapListStep';
|
|
12
|
-
import { wrapBlockquoteToDecisionListStep } from './steps/wrapBlockquoteToDecisionListStep';
|
|
13
|
-
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
14
|
-
import { getNodeName, NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
15
|
-
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
16
|
-
import { unwrapStep } from './unwrapStep';
|
|
17
|
-
import { wrapIntoListStep } from './wrapIntoListStep';
|
|
18
|
-
import { wrapStep } from './wrapStep';
|
|
19
|
-
|
|
20
|
-
// Transform steps for combinations of node categories (block/container/list/text)
|
|
21
|
-
var TRANSFORM_STEPS = {
|
|
22
|
-
atomic: {
|
|
23
|
-
atomic: undefined,
|
|
24
|
-
container: [wrapStep],
|
|
25
|
-
list: [wrapIntoListStep],
|
|
26
|
-
text: undefined,
|
|
27
|
-
multi: undefined
|
|
28
|
-
},
|
|
29
|
-
container: {
|
|
30
|
-
atomic: undefined,
|
|
31
|
-
container: [unwrapStep, wrapStep],
|
|
32
|
-
list: undefined,
|
|
33
|
-
text: [unwrapStep],
|
|
34
|
-
multi: undefined
|
|
35
|
-
},
|
|
36
|
-
list: {
|
|
37
|
-
atomic: undefined,
|
|
38
|
-
container: [wrapStep],
|
|
39
|
-
list: [listToListStep],
|
|
40
|
-
text: [flattenListStep, unwrapListStep, applyTargetTextTypeStep],
|
|
41
|
-
multi: undefined
|
|
42
|
-
},
|
|
43
|
-
text: {
|
|
44
|
-
atomic: undefined,
|
|
45
|
-
container: [wrapMixedContentStep],
|
|
46
|
-
list: [wrapIntoListStep],
|
|
47
|
-
text: [flattenStep, applyTargetTextTypeStep],
|
|
48
|
-
multi: undefined
|
|
49
|
-
},
|
|
50
|
-
multi: {
|
|
51
|
-
atomic: undefined,
|
|
52
|
-
container: [wrapMixedContentStep],
|
|
53
|
-
list: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
54
|
-
text: [convertEachNodeStep],
|
|
55
|
-
multi: undefined
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Transform steps for specific pairs of node types that cannot be processed
|
|
60
|
-
// using generic rules/steps from TRANSFORM_STEPS.
|
|
61
|
-
// Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
|
|
62
|
-
var TRANSFORM_STEPS_OVERRIDE = {
|
|
63
|
-
paragraph: {
|
|
64
|
-
paragraph: null
|
|
65
|
-
},
|
|
66
|
-
heading: {},
|
|
67
|
-
panel: {
|
|
68
|
-
panel: null,
|
|
69
|
-
layoutSection: [unwrapStep, wrapMixedContentStep],
|
|
70
|
-
codeBlock: [unwrapStep, wrapMixedContentStep],
|
|
71
|
-
blockquote: [unwrapStep, wrapMixedContentStep],
|
|
72
|
-
taskList: null,
|
|
73
|
-
bulletList: null,
|
|
74
|
-
orderedList: null,
|
|
75
|
-
heading: null
|
|
76
|
-
},
|
|
77
|
-
expand: {
|
|
78
|
-
expand: null,
|
|
79
|
-
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
80
|
-
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
81
|
-
layoutSection: [unwrapExpandStep, wrapMixedContentStep],
|
|
82
|
-
paragraph: [unwrapExpandStep],
|
|
83
|
-
codeBlock: null,
|
|
84
|
-
heading: null
|
|
85
|
-
},
|
|
86
|
-
nestedExpand: {
|
|
87
|
-
expand: null,
|
|
88
|
-
nestedExpand: null,
|
|
89
|
-
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
90
|
-
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
91
|
-
paragraph: [unwrapExpandStep],
|
|
92
|
-
codeBlock: null,
|
|
93
|
-
heading: null
|
|
94
|
-
},
|
|
95
|
-
blockquote: {
|
|
96
|
-
blockquote: null,
|
|
97
|
-
expand: [wrapStep],
|
|
98
|
-
nestedExpand: [wrapStep],
|
|
99
|
-
layoutSection: [wrapMixedContentStep],
|
|
100
|
-
codeBlock: null,
|
|
101
|
-
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep],
|
|
102
|
-
paragraph: [unwrapStep],
|
|
103
|
-
heading: [unwrapStep, applyTargetTextTypeStep]
|
|
104
|
-
},
|
|
105
|
-
layoutSection: {
|
|
106
|
-
layoutSection: null,
|
|
107
|
-
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
108
|
-
expand: [unwrapLayoutStep, wrapStep],
|
|
109
|
-
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
110
|
-
codeBlock: null,
|
|
111
|
-
paragraph: [unwrapLayoutStep],
|
|
112
|
-
heading: null
|
|
113
|
-
},
|
|
114
|
-
codeBlock: {
|
|
115
|
-
codeBlock: null,
|
|
116
|
-
blockquote: [wrapStep],
|
|
117
|
-
expand: [wrapStep],
|
|
118
|
-
nestedExpand: [wrapStep],
|
|
119
|
-
layoutSection: [wrapMixedContentStep],
|
|
120
|
-
panel: [wrapStep],
|
|
121
|
-
paragraph: [applyTargetTextTypeStep],
|
|
122
|
-
heading: null
|
|
123
|
-
},
|
|
124
|
-
bulletList: {
|
|
125
|
-
bulletList: null,
|
|
126
|
-
codeBlock: null,
|
|
127
|
-
layoutSection: [wrapMixedContentStep],
|
|
128
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
129
|
-
heading: null
|
|
130
|
-
},
|
|
131
|
-
orderedList: {
|
|
132
|
-
orderedList: null,
|
|
133
|
-
codeBlock: null,
|
|
134
|
-
layoutSection: [wrapMixedContentStep],
|
|
135
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
136
|
-
heading: null
|
|
137
|
-
},
|
|
138
|
-
taskList: {
|
|
139
|
-
blockquote: null,
|
|
140
|
-
codeBlock: null,
|
|
141
|
-
layoutSection: [wrapMixedContentStep],
|
|
142
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
143
|
-
heading: null,
|
|
144
|
-
taskList: null
|
|
145
|
-
},
|
|
146
|
-
table: {
|
|
147
|
-
layoutSection: [wrapMixedContentStep],
|
|
148
|
-
blockquote: null,
|
|
149
|
-
panel: null,
|
|
150
|
-
codeBlock: null,
|
|
151
|
-
orderedList: null,
|
|
152
|
-
bulletList: null,
|
|
153
|
-
taskList: null,
|
|
154
|
-
decisionList: null
|
|
155
|
-
},
|
|
156
|
-
mediaSingle: {
|
|
157
|
-
layoutSection: [wrapMixedContentStep],
|
|
158
|
-
codeBlock: null,
|
|
159
|
-
decisionList: null,
|
|
160
|
-
taskList: null
|
|
161
|
-
},
|
|
162
|
-
mediaGroup: {
|
|
163
|
-
layoutSection: [wrapMixedContentStep],
|
|
164
|
-
codeBlock: null,
|
|
165
|
-
decisionList: null,
|
|
166
|
-
bulletList: null,
|
|
167
|
-
orderedList: null,
|
|
168
|
-
taskList: null
|
|
169
|
-
},
|
|
170
|
-
decisionList: {
|
|
171
|
-
decisionList: null,
|
|
172
|
-
bulletList: [decisionListToListStep],
|
|
173
|
-
orderedList: [decisionListToListStep],
|
|
174
|
-
taskList: [decisionListToListStep],
|
|
175
|
-
layoutSection: [wrapMixedContentStep],
|
|
176
|
-
blockquote: [unwrapListStep, wrapStep],
|
|
177
|
-
codeBlock: [unwrapListStep, wrapMixedContentStep]
|
|
178
|
-
},
|
|
179
|
-
blockCard: {
|
|
180
|
-
layoutSection: [wrapMixedContentStep],
|
|
181
|
-
blockquote: null,
|
|
182
|
-
codeBlock: null,
|
|
183
|
-
orderedList: null,
|
|
184
|
-
bulletList: null,
|
|
185
|
-
taskList: null,
|
|
186
|
-
decisionList: null
|
|
187
|
-
},
|
|
188
|
-
embedCard: {
|
|
189
|
-
layoutSection: [wrapMixedContentStep],
|
|
190
|
-
blockquote: null,
|
|
191
|
-
panel: null,
|
|
192
|
-
codeBlock: null,
|
|
193
|
-
orderedList: null,
|
|
194
|
-
bulletList: null,
|
|
195
|
-
taskList: null,
|
|
196
|
-
decisionList: null
|
|
197
|
-
},
|
|
198
|
-
extension: {
|
|
199
|
-
layoutSection: [wrapMixedContentStep],
|
|
200
|
-
codeBlock: null,
|
|
201
|
-
decisionList: null,
|
|
202
|
-
taskList: null,
|
|
203
|
-
orderedList: null,
|
|
204
|
-
bulletList: null
|
|
205
|
-
},
|
|
206
|
-
bodiedExtension: {
|
|
207
|
-
layoutSection: [wrapMixedContentStep],
|
|
208
|
-
blockquote: null,
|
|
209
|
-
expand: null,
|
|
210
|
-
panel: null,
|
|
211
|
-
codeBlock: null,
|
|
212
|
-
orderedList: null,
|
|
213
|
-
bulletList: null,
|
|
214
|
-
taskList: null,
|
|
215
|
-
decisionList: null
|
|
216
|
-
},
|
|
217
|
-
multi: {
|
|
218
|
-
heading: [applyTargetTextTypeStep]
|
|
219
|
-
// Similar to heading, all structures are kept as is
|
|
220
|
-
// EG: transformed: other lists, paragarph, headings
|
|
221
|
-
// eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
|
|
222
|
-
// decisionList: [],
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
226
|
-
var _TRANSFORM_STEPS_OVER;
|
|
227
|
-
var fromCategory = NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
|
|
228
|
-
var toCategory = NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
|
|
229
|
-
var overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
|
|
230
|
-
if (overrideSteps === null) {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
var steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
|
|
234
|
-
return steps;
|
|
235
|
-
};
|
|
2
|
+
import { TRANSFORMATION_MATRIX } from './TRANSFORMATION_MATRIX';
|
|
3
|
+
import { getNodeName, toNodeTypeValue } from './types';
|
|
236
4
|
/**
|
|
237
5
|
* Convert a list of nodes to a target node type.
|
|
238
6
|
* If no steps are found, the source nodes are returned unchanged.
|
|
@@ -265,7 +33,7 @@ export var convertNodesToTargetType = function convertNodesToTargetType(_ref) {
|
|
|
265
33
|
if (!selectedNodeTypeName || !targetNodeTypeName) {
|
|
266
34
|
return sourceNodes;
|
|
267
35
|
}
|
|
268
|
-
var steps =
|
|
36
|
+
var steps = TRANSFORMATION_MATRIX[selectedNodeTypeName][targetNodeTypeName];
|
|
269
37
|
var context = {
|
|
270
38
|
// sourceNode is incorrect now - what to do here?
|
|
271
39
|
fromNode: sourceNode,
|
|
@@ -281,9 +49,6 @@ export var convertNodesToTargetType = function convertNodesToTargetType(_ref) {
|
|
|
281
49
|
}, sourceNodes);
|
|
282
50
|
};
|
|
283
51
|
export var isTransformDisabledBasedOnStepsConfig = function isTransformDisabledBasedOnStepsConfig(selectedNodeType, targetNodeType) {
|
|
284
|
-
var steps =
|
|
285
|
-
|
|
286
|
-
return true;
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
52
|
+
var steps = TRANSFORMATION_MATRIX[selectedNodeType][targetNodeType];
|
|
53
|
+
return !steps || steps.length === 0;
|
|
289
54
|
};
|
|
@@ -12,6 +12,8 @@ import { MoveDownDropdownItem } from './move-down';
|
|
|
12
12
|
import { MoveUpDropdownItem } from './move-up';
|
|
13
13
|
import { SuggestedItemsMenuSection } from './suggested-items-menu-section';
|
|
14
14
|
import { SuggestedMenuItems } from './suggested-menu-items';
|
|
15
|
+
import { createMenuItemsMap } from './utils/createMenuItemsMap';
|
|
16
|
+
import { getSuggestedItemsFromSelection } from './utils/getSuggestedItemsFromSelection';
|
|
15
17
|
var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
|
|
16
18
|
return [{
|
|
17
19
|
type: 'block-menu-item',
|
|
@@ -88,6 +90,16 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
|
|
|
88
90
|
return /*#__PURE__*/React.createElement(SuggestedMenuItems, {
|
|
89
91
|
api: api
|
|
90
92
|
});
|
|
93
|
+
},
|
|
94
|
+
isHidden: function isHidden() {
|
|
95
|
+
var _api$blockMenu, _api$selection, _api$blockControls;
|
|
96
|
+
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
97
|
+
var menuItemsMap = createMenuItemsMap(blockMenuComponents);
|
|
98
|
+
var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
|
|
99
|
+
var preservedSelection = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.sharedState.currentState()) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.preservedSelection;
|
|
100
|
+
var currentSelection = preservedSelection || selection;
|
|
101
|
+
var suggestedItems = getSuggestedItemsFromSelection(menuItemsMap, currentSelection);
|
|
102
|
+
return suggestedItems.length === 0;
|
|
91
103
|
}
|
|
92
104
|
}, {
|
|
93
105
|
type: 'block-menu-section',
|
|
@@ -8,15 +8,15 @@ export var BlockMenuComponent = function BlockMenuComponent(_ref) {
|
|
|
8
8
|
var registeredComponent = _ref.registeredComponent,
|
|
9
9
|
childrenMap = _ref.childrenMap,
|
|
10
10
|
fallbacks = _ref.fallbacks;
|
|
11
|
+
if (!willComponentRender(registeredComponent, childrenMap)) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
11
14
|
if (registeredComponent.type === 'block-menu-item') {
|
|
12
15
|
var ItemComponent = registeredComponent.component || fallbacks['block-menu-item'];
|
|
13
16
|
return /*#__PURE__*/React.createElement(ItemComponent, {
|
|
14
17
|
key: registeredComponent.key
|
|
15
18
|
});
|
|
16
19
|
}
|
|
17
|
-
if (!willComponentRender(registeredComponent, childrenMap)) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
20
|
var ParentComponent = registeredComponent.component || fallbacks[registeredComponent.type];
|
|
21
21
|
var childrenMapKey = getChildrenMapKey(registeredComponent.key, registeredComponent.type);
|
|
22
22
|
var registeredComponents = childrenMap.get(childrenMapKey);
|
|
@@ -99,21 +99,18 @@ export var buildChildrenMap = function buildChildrenMap(components) {
|
|
|
99
99
|
* Determines whether a component will render based on its type and children
|
|
100
100
|
*
|
|
101
101
|
* Rules:
|
|
102
|
-
* - An item will not render if has
|
|
103
|
-
* - A nested menu will render if
|
|
102
|
+
* - An item will not render if it has isHidden that returns true OR if its component returns null (fallback)
|
|
103
|
+
* - A nested menu will render if at least one section, that has at least one registered child
|
|
104
104
|
* - A section will render if it has at least one registered child component that will render
|
|
105
105
|
*
|
|
106
|
-
* NOTE: This requires invoking each item's component function to check for null return
|
|
107
106
|
*/
|
|
108
107
|
var _willComponentRender = function willComponentRender(registeredComponent, childrenMap) {
|
|
109
108
|
if (registeredComponent.type === 'block-menu-item') {
|
|
110
|
-
|
|
109
|
+
var _registeredComponent$;
|
|
110
|
+
return !(registeredComponent !== null && registeredComponent !== void 0 && (_registeredComponent$ = registeredComponent.isHidden) !== null && _registeredComponent$ !== void 0 && _registeredComponent$.call(registeredComponent));
|
|
111
111
|
}
|
|
112
112
|
var childrenMapKey = getChildrenMapKey(registeredComponent.key, registeredComponent.type);
|
|
113
113
|
var registeredComponents = childrenMap.get(childrenMapKey) || [];
|
|
114
|
-
if (registeredComponent.type === 'block-menu-nested') {
|
|
115
|
-
return registeredComponents.length > 0;
|
|
116
|
-
}
|
|
117
114
|
return registeredComponents.some(function (childComponent) {
|
|
118
115
|
return _willComponentRender(childComponent, childrenMap);
|
|
119
116
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getSortedSuggestedItems } from '../utils/suggested-items-rank';
|
|
3
|
+
import { createMenuItemsMap } from '../utils/createMenuItemsMap';
|
|
4
|
+
import { getSuggestedItemsFromSelection } from '../utils/getSuggestedItemsFromSelection';
|
|
6
5
|
export var useSuggestedItems = function useSuggestedItems(api) {
|
|
7
6
|
var _api$blockMenu;
|
|
8
7
|
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls', 'selection'], function (states) {
|
|
@@ -16,43 +15,11 @@ export var useSuggestedItems = function useSuggestedItems(api) {
|
|
|
16
15
|
selection = _useSharedPluginState.selection;
|
|
17
16
|
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
18
17
|
var menuItemsMap = useMemo(function () {
|
|
19
|
-
|
|
20
|
-
return new Map();
|
|
21
|
-
}
|
|
22
|
-
return new Map(blockMenuComponents.filter(function (c) {
|
|
23
|
-
return c.type === 'block-menu-item';
|
|
24
|
-
}).map(function (item) {
|
|
25
|
-
return [item.key, item];
|
|
26
|
-
}));
|
|
18
|
+
return createMenuItemsMap(blockMenuComponents);
|
|
27
19
|
}, [blockMenuComponents]);
|
|
28
20
|
var suggestedItems = useMemo(function () {
|
|
29
21
|
var currentSelection = preservedSelection || selection;
|
|
30
|
-
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
var _expandSelectionToBlo = expandSelectionToBlockRange(currentSelection),
|
|
34
|
-
range = _expandSelectionToBlo.range;
|
|
35
|
-
if (!range) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
var blockNodes = getBlockNodesInRange(range);
|
|
39
|
-
if (blockNodes.length === 0) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
var firstNodeType = blockNodes[0].type.name;
|
|
43
|
-
var allSameType = blockNodes.every(function (node) {
|
|
44
|
-
return node.type.name === firstNodeType;
|
|
45
|
-
});
|
|
46
|
-
if (!allSameType) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
var nodeTypeName = firstNodeType;
|
|
50
|
-
var sortedKeys = getSortedSuggestedItems(nodeTypeName);
|
|
51
|
-
return sortedKeys.map(function (key) {
|
|
52
|
-
return menuItemsMap.get(key);
|
|
53
|
-
}).filter(function (item) {
|
|
54
|
-
return item !== undefined;
|
|
55
|
-
});
|
|
22
|
+
return getSuggestedItemsFromSelection(menuItemsMap, currentSelection);
|
|
56
23
|
}, [menuItemsMap, preservedSelection, selection]);
|
|
57
24
|
return suggestedItems;
|
|
58
25
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to create menu items map from block menu components.
|
|
3
|
+
*/
|
|
4
|
+
export var createMenuItemsMap = function createMenuItemsMap(blockMenuComponents) {
|
|
5
|
+
if (!blockMenuComponents) {
|
|
6
|
+
return new Map();
|
|
7
|
+
}
|
|
8
|
+
return new Map(blockMenuComponents.filter(function (c) {
|
|
9
|
+
return c.type === 'block-menu-item';
|
|
10
|
+
}).map(function (item) {
|
|
11
|
+
return [item.key, item];
|
|
12
|
+
}));
|
|
13
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { getBlockNodesInRange } from '../../editor-commands/transform-node-utils/utils';
|
|
3
|
+
import { getSortedSuggestedItems } from '../utils/suggested-items-rank';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pure function to calculate suggested items based on selection and menu components.
|
|
7
|
+
*/
|
|
8
|
+
export var getSuggestedItemsFromSelection = function getSuggestedItemsFromSelection(menuItemsMap, currentSelection) {
|
|
9
|
+
if (menuItemsMap.size === 0 || !currentSelection) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
var _expandSelectionToBlo = expandSelectionToBlockRange(currentSelection),
|
|
13
|
+
range = _expandSelectionToBlo.range;
|
|
14
|
+
if (!range) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
var blockNodes = getBlockNodesInRange(range);
|
|
18
|
+
if (blockNodes.length === 0) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
var firstNodeType = blockNodes[0].type.name;
|
|
22
|
+
var allSameType = blockNodes.every(function (node) {
|
|
23
|
+
return node.type.name === firstNodeType;
|
|
24
|
+
});
|
|
25
|
+
if (!allSameType) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
var nodeTypeName = firstNodeType;
|
|
29
|
+
var sortedKeys = getSortedSuggestedItems(nodeTypeName);
|
|
30
|
+
return sortedKeys.map(function (key) {
|
|
31
|
+
return menuItemsMap.get(key);
|
|
32
|
+
}).filter(function (item) {
|
|
33
|
+
return item !== undefined;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -106,6 +106,7 @@ export type RegisterBlockMenuSection = BlockMenuSection & {
|
|
|
106
106
|
};
|
|
107
107
|
export type RegisterBlockMenuItem = BlockMenuItem & {
|
|
108
108
|
component?: BlockMenuItemComponent;
|
|
109
|
+
isHidden?: () => boolean;
|
|
109
110
|
parent: Parent<BlockMenuSection>;
|
|
110
111
|
};
|
|
111
112
|
export type RegisterBlockMenuComponent = RegisterBlockMenuNested | RegisterBlockMenuSection | RegisterBlockMenuItem;
|
|
@@ -28,10 +28,9 @@ export declare const buildChildrenMap: (components: RegisterBlockMenuComponent[]
|
|
|
28
28
|
* Determines whether a component will render based on its type and children
|
|
29
29
|
*
|
|
30
30
|
* Rules:
|
|
31
|
-
* - An item will not render if has
|
|
32
|
-
* - A nested menu will render if
|
|
31
|
+
* - An item will not render if it has isHidden that returns true OR if its component returns null (fallback)
|
|
32
|
+
* - A nested menu will render if at least one section, that has at least one registered child
|
|
33
33
|
* - A section will render if it has at least one registered child component that will render
|
|
34
34
|
*
|
|
35
|
-
* NOTE: This requires invoking each item's component function to check for null return
|
|
36
35
|
*/
|
|
37
36
|
export declare const willComponentRender: (registeredComponent: RegisterBlockMenuComponent, childrenMap: ChildrenMap) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { BlockMenuPlugin, RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to create menu items map from block menu components.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createMenuItemsMap: (blockMenuComponents: ReturnType<ExtractInjectionAPI<BlockMenuPlugin>["blockMenu"]["actions"]["getBlockMenuComponents"]> | undefined) => Map<string, RegisterBlockMenuItem>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* Pure function to calculate suggested items based on selection and menu components.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getSuggestedItemsFromSelection: (menuItemsMap: Map<string, RegisterBlockMenuItem>, currentSelection: Selection | null | undefined) => RegisterBlockMenuItem[];
|
|
@@ -106,6 +106,7 @@ export type RegisterBlockMenuSection = BlockMenuSection & {
|
|
|
106
106
|
};
|
|
107
107
|
export type RegisterBlockMenuItem = BlockMenuItem & {
|
|
108
108
|
component?: BlockMenuItemComponent;
|
|
109
|
+
isHidden?: () => boolean;
|
|
109
110
|
parent: Parent<BlockMenuSection>;
|
|
110
111
|
};
|
|
111
112
|
export type RegisterBlockMenuComponent = RegisterBlockMenuNested | RegisterBlockMenuSection | RegisterBlockMenuItem;
|
|
@@ -28,10 +28,9 @@ export declare const buildChildrenMap: (components: RegisterBlockMenuComponent[]
|
|
|
28
28
|
* Determines whether a component will render based on its type and children
|
|
29
29
|
*
|
|
30
30
|
* Rules:
|
|
31
|
-
* - An item will not render if has
|
|
32
|
-
* - A nested menu will render if
|
|
31
|
+
* - An item will not render if it has isHidden that returns true OR if its component returns null (fallback)
|
|
32
|
+
* - A nested menu will render if at least one section, that has at least one registered child
|
|
33
33
|
* - A section will render if it has at least one registered child component that will render
|
|
34
34
|
*
|
|
35
|
-
* NOTE: This requires invoking each item's component function to check for null return
|
|
36
35
|
*/
|
|
37
36
|
export declare const willComponentRender: (registeredComponent: RegisterBlockMenuComponent, childrenMap: ChildrenMap) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { BlockMenuPlugin, RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to create menu items map from block menu components.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createMenuItemsMap: (blockMenuComponents: ReturnType<ExtractInjectionAPI<BlockMenuPlugin>["blockMenu"]["actions"]["getBlockMenuComponents"]> | undefined) => Map<string, RegisterBlockMenuItem>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { RegisterBlockMenuItem } from '../../blockMenuPluginType';
|
|
3
|
+
/**
|
|
4
|
+
* Pure function to calculate suggested items based on selection and menu components.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getSuggestedItemsFromSelection: (menuItemsMap: Map<string, RegisterBlockMenuItem>, currentSelection: Selection | null | undefined) => RegisterBlockMenuItem[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.12",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"@atlaskit/editor-prosemirror": "^7.2.0",
|
|
39
39
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
40
40
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
41
|
-
"@atlaskit/editor-toolbar": "^0.
|
|
42
|
-
"@atlaskit/flag": "^17.
|
|
43
|
-
"@atlaskit/icon": "^29.
|
|
41
|
+
"@atlaskit/editor-toolbar": "^0.19.0",
|
|
42
|
+
"@atlaskit/flag": "^17.8.0",
|
|
43
|
+
"@atlaskit/icon": "^29.4.0",
|
|
44
44
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
45
45
|
"@atlaskit/platform-feature-flags-react": "^0.4.0",
|
|
46
46
|
"@atlaskit/primitives": "^17.0.0",
|
|
47
|
-
"@atlaskit/tmp-editor-statsig": "^16.
|
|
47
|
+
"@atlaskit/tmp-editor-statsig": "^16.11.0",
|
|
48
48
|
"@atlaskit/tokens": "^9.1.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@atlaskit/editor-common": "^111.
|
|
52
|
+
"@atlaskit/editor-common": "^111.7.0",
|
|
53
53
|
"react": "^18.2.0",
|
|
54
54
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
55
55
|
},
|