@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +224 -0
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
  4. package/dist/cjs/editor-commands/transform-node-utils/transform.js +4 -238
  5. package/dist/cjs/ui/block-menu-components.js +12 -0
  6. package/dist/cjs/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
  7. package/dist/cjs/ui/block-menu-renderer/utils.js +4 -7
  8. package/dist/cjs/ui/hooks/useSuggestedItems.js +4 -37
  9. package/dist/cjs/ui/utils/createMenuItemsMap.js +19 -0
  10. package/dist/cjs/ui/utils/getSuggestedItemsFromSelection.js +40 -0
  11. package/dist/es2019/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
  12. package/dist/es2019/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +56 -1
  13. package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -240
  14. package/dist/es2019/ui/block-menu-components.js +13 -1
  15. package/dist/es2019/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
  16. package/dist/es2019/ui/block-menu-renderer/utils.js +4 -7
  17. package/dist/es2019/ui/hooks/useSuggestedItems.js +4 -28
  18. package/dist/es2019/ui/utils/createMenuItemsMap.js +9 -0
  19. package/dist/es2019/ui/utils/getSuggestedItemsFromSelection.js +30 -0
  20. package/dist/esm/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
  21. package/dist/esm/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
  22. package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -240
  23. package/dist/esm/ui/block-menu-components.js +12 -0
  24. package/dist/esm/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
  25. package/dist/esm/ui/block-menu-renderer/utils.js +4 -7
  26. package/dist/esm/ui/hooks/useSuggestedItems.js +4 -37
  27. package/dist/esm/ui/utils/createMenuItemsMap.js +13 -0
  28. package/dist/esm/ui/utils/getSuggestedItemsFromSelection.js +35 -0
  29. package/dist/types/blockMenuPluginType.d.ts +1 -0
  30. package/dist/types/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
  31. package/dist/types/ui/block-menu-renderer/utils.d.ts +2 -3
  32. package/dist/types/ui/utils/createMenuItemsMap.d.ts +6 -0
  33. package/dist/types/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
  34. package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -0
  35. package/dist/types-ts4.5/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
  36. package/dist/types-ts4.5/ui/block-menu-renderer/utils.d.ts +2 -3
  37. package/dist/types-ts4.5/ui/utils/createMenuItemsMap.d.ts +6 -0
  38. package/dist/types-ts4.5/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
  39. package/package.json +6 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 6.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b909e5f47ea91`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b909e5f47ea91) -
8
+ EDITOR-4159 Make sure block-menu-item type component return null when tranform disabled
9
+ - Updated dependencies
10
+
11
+ ## 6.0.11
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
17
+ ## 6.0.10
18
+
19
+ ### Patch Changes
20
+
21
+ - [`b512bf962fe38`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b512bf962fe38) -
22
+ [ux] codeblock transformations should drop any incompatible content, it should just be wrapped
23
+ - Updated dependencies
24
+
3
25
  ## 6.0.9
4
26
 
5
27
  ### Patch Changes
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TRANSFORMATION_MATRIX = void 0;
7
+ var _flattenStep = require("./flattenStep");
8
+ var _applyTargetTextTypeStep = require("./steps/applyTargetTextTypeStep");
9
+ var _convertEachNodeStep = require("./steps/convertEachNodeStep");
10
+ var _decisionListToListStep = require("./steps/decisionListToListStep");
11
+ var _flattenListStep = require("./steps/flattenListStep");
12
+ var _listToDecisionListStep = require("./steps/listToDecisionListStep");
13
+ var _listToListStep = require("./steps/listToListStep");
14
+ var _mergeNeighbourListsStep = require("./steps/mergeNeighbourListsStep");
15
+ var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
16
+ var _unwrapListStep = require("./steps/unwrapListStep");
17
+ var _wrapBlockquoteToDecisionListStep = require("./steps/wrapBlockquoteToDecisionListStep");
18
+ var _wrapMixedContentStep = require("./steps/wrapMixedContentStep");
19
+ var _unwrapExpandStep = require("./unwrapExpandStep");
20
+ var _unwrapStep = require("./unwrapStep");
21
+ var _wrapIntoListStep = require("./wrapIntoListStep");
22
+ var _wrapStep = require("./wrapStep");
23
+ // Transform steps for all node type pairs.
24
+ // If a transformation is not defined (undefined), it is not available.
25
+ var TRANSFORMATION_MATRIX = exports.TRANSFORMATION_MATRIX = {
26
+ paragraph: {
27
+ heading: [_flattenStep.flattenStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
28
+ blockquote: [_wrapMixedContentStep.wrapMixedContentStep],
29
+ codeBlock: [_wrapMixedContentStep.wrapMixedContentStep],
30
+ expand: [_wrapMixedContentStep.wrapMixedContentStep],
31
+ nestedExpand: [_wrapMixedContentStep.wrapMixedContentStep],
32
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
33
+ panel: [_wrapMixedContentStep.wrapMixedContentStep],
34
+ bulletList: [_wrapIntoListStep.wrapIntoListStep],
35
+ orderedList: [_wrapIntoListStep.wrapIntoListStep],
36
+ taskList: [_wrapIntoListStep.wrapIntoListStep],
37
+ decisionList: [_wrapIntoListStep.wrapIntoListStep]
38
+ },
39
+ heading: {
40
+ heading: [_flattenStep.flattenStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
41
+ paragraph: [_flattenStep.flattenStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
42
+ blockquote: [_wrapMixedContentStep.wrapMixedContentStep],
43
+ codeBlock: [_wrapMixedContentStep.wrapMixedContentStep],
44
+ expand: [_wrapMixedContentStep.wrapMixedContentStep],
45
+ nestedExpand: [_wrapMixedContentStep.wrapMixedContentStep],
46
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
47
+ panel: [_wrapMixedContentStep.wrapMixedContentStep],
48
+ bulletList: [_wrapIntoListStep.wrapIntoListStep],
49
+ orderedList: [_wrapIntoListStep.wrapIntoListStep],
50
+ taskList: [_wrapIntoListStep.wrapIntoListStep],
51
+ decisionList: [_wrapIntoListStep.wrapIntoListStep]
52
+ },
53
+ panel: {
54
+ blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
55
+ codeBlock: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
56
+ expand: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
57
+ nestedExpand: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
58
+ layoutSection: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
59
+ paragraph: [_unwrapStep.unwrapStep]
60
+ },
61
+ expand: {
62
+ panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
63
+ blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
64
+ layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
65
+ nestedExpand: [_unwrapExpandStep.unwrapExpandStep, _wrapStep.wrapStep],
66
+ paragraph: [_unwrapExpandStep.unwrapExpandStep]
67
+ },
68
+ nestedExpand: {
69
+ panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
70
+ blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
71
+ layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
72
+ paragraph: [_unwrapExpandStep.unwrapExpandStep]
73
+ },
74
+ blockquote: {
75
+ expand: [_wrapStep.wrapStep],
76
+ nestedExpand: [_wrapStep.wrapStep],
77
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
78
+ panel: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
79
+ paragraph: [_unwrapStep.unwrapStep],
80
+ heading: [_unwrapStep.unwrapStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
81
+ decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
82
+ },
83
+ layoutSection: {
84
+ blockquote: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
85
+ expand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
86
+ nestedExpand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
87
+ panel: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
88
+ paragraph: [_unwrapLayoutStep.unwrapLayoutStep]
89
+ },
90
+ codeBlock: {
91
+ blockquote: [_wrapStep.wrapStep],
92
+ expand: [_wrapStep.wrapStep],
93
+ nestedExpand: [_wrapStep.wrapStep],
94
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
95
+ panel: [_wrapStep.wrapStep],
96
+ paragraph: [_applyTargetTextTypeStep.applyTargetTextTypeStep]
97
+ },
98
+ bulletList: {
99
+ orderedList: [_listToListStep.listToListStep],
100
+ taskList: [_listToListStep.listToListStep],
101
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
102
+ blockquote: [_wrapStep.wrapStep],
103
+ expand: [_wrapStep.wrapStep],
104
+ nestedExpand: [_wrapStep.wrapStep],
105
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
106
+ panel: [_wrapStep.wrapStep],
107
+ paragraph: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
108
+ },
109
+ orderedList: {
110
+ bulletList: [_listToListStep.listToListStep],
111
+ taskList: [_listToListStep.listToListStep],
112
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
113
+ blockquote: [_wrapStep.wrapStep],
114
+ expand: [_wrapStep.wrapStep],
115
+ nestedExpand: [_wrapStep.wrapStep],
116
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
117
+ panel: [_wrapStep.wrapStep],
118
+ paragraph: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
119
+ },
120
+ taskList: {
121
+ bulletList: [_listToListStep.listToListStep],
122
+ orderedList: [_listToListStep.listToListStep],
123
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
124
+ expand: [_wrapStep.wrapStep],
125
+ nestedExpand: [_wrapStep.wrapStep],
126
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
127
+ panel: [_wrapStep.wrapStep],
128
+ paragraph: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
129
+ },
130
+ table: {
131
+ expand: [_wrapStep.wrapStep],
132
+ nestedExpand: [_wrapStep.wrapStep],
133
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
134
+ },
135
+ mediaSingle: {
136
+ blockquote: [_wrapStep.wrapStep],
137
+ expand: [_wrapStep.wrapStep],
138
+ nestedExpand: [_wrapStep.wrapStep],
139
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
140
+ panel: [_wrapStep.wrapStep],
141
+ bulletList: [_wrapIntoListStep.wrapIntoListStep],
142
+ orderedList: [_wrapIntoListStep.wrapIntoListStep]
143
+ },
144
+ mediaGroup: {
145
+ blockquote: [_wrapStep.wrapStep],
146
+ expand: [_wrapStep.wrapStep],
147
+ nestedExpand: [_wrapStep.wrapStep],
148
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
149
+ panel: [_wrapStep.wrapStep]
150
+ },
151
+ media: {
152
+ blockquote: [_wrapStep.wrapStep],
153
+ codeBlock: [_wrapStep.wrapStep],
154
+ expand: [_wrapStep.wrapStep],
155
+ nestedExpand: [_wrapStep.wrapStep],
156
+ layoutSection: [_wrapStep.wrapStep],
157
+ panel: [_wrapStep.wrapStep],
158
+ bulletList: [_wrapIntoListStep.wrapIntoListStep],
159
+ orderedList: [_wrapIntoListStep.wrapIntoListStep],
160
+ taskList: [_wrapIntoListStep.wrapIntoListStep],
161
+ decisionList: [_wrapIntoListStep.wrapIntoListStep]
162
+ },
163
+ decisionList: {
164
+ bulletList: [_decisionListToListStep.decisionListToListStep],
165
+ orderedList: [_decisionListToListStep.decisionListToListStep],
166
+ taskList: [_decisionListToListStep.decisionListToListStep],
167
+ blockquote: [_unwrapListStep.unwrapListStep, _wrapStep.wrapStep],
168
+ codeBlock: [_unwrapListStep.unwrapListStep, _wrapMixedContentStep.wrapMixedContentStep],
169
+ expand: [_wrapStep.wrapStep],
170
+ nestedExpand: [_wrapStep.wrapStep],
171
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
172
+ panel: [_wrapStep.wrapStep],
173
+ paragraph: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
174
+ heading: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
175
+ },
176
+ blockCard: {
177
+ expand: [_wrapStep.wrapStep],
178
+ nestedExpand: [_wrapStep.wrapStep],
179
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
180
+ panel: [_wrapStep.wrapStep]
181
+ },
182
+ embedCard: {
183
+ expand: [_wrapStep.wrapStep],
184
+ nestedExpand: [_wrapStep.wrapStep],
185
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
186
+ },
187
+ extension: {
188
+ blockquote: [_wrapStep.wrapStep],
189
+ expand: [_wrapStep.wrapStep],
190
+ nestedExpand: [_wrapStep.wrapStep],
191
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
192
+ panel: [_wrapStep.wrapStep]
193
+ },
194
+ bodiedExtension: {
195
+ nestedExpand: [_wrapStep.wrapStep],
196
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
197
+ },
198
+ multiBodiedExtension: {
199
+ blockquote: [_wrapStep.wrapStep],
200
+ codeBlock: [_wrapStep.wrapStep],
201
+ expand: [_wrapStep.wrapStep],
202
+ nestedExpand: [_wrapStep.wrapStep],
203
+ layoutSection: [_wrapStep.wrapStep],
204
+ panel: [_wrapStep.wrapStep],
205
+ bulletList: [_wrapIntoListStep.wrapIntoListStep],
206
+ orderedList: [_wrapIntoListStep.wrapIntoListStep],
207
+ taskList: [_wrapIntoListStep.wrapIntoListStep],
208
+ decisionList: [_wrapIntoListStep.wrapIntoListStep]
209
+ },
210
+ multi: {
211
+ blockquote: [_wrapMixedContentStep.wrapMixedContentStep],
212
+ codeBlock: [_wrapMixedContentStep.wrapMixedContentStep],
213
+ expand: [_wrapMixedContentStep.wrapMixedContentStep],
214
+ nestedExpand: [_wrapMixedContentStep.wrapMixedContentStep],
215
+ layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
216
+ panel: [_wrapMixedContentStep.wrapMixedContentStep],
217
+ bulletList: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
218
+ orderedList: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
219
+ taskList: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
220
+ decisionList: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
221
+ paragraph: [_convertEachNodeStep.convertEachNodeStep],
222
+ heading: [_applyTargetTextTypeStep.applyTargetTextTypeStep]
223
+ }
224
+ };
@@ -10,6 +10,46 @@ var _transform = require("../transform");
10
10
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
11
11
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
12
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ /**
14
+ * Handles the edge case where transforming multi-selection to decisionList results in
15
+ * all content breaking out (no valid children for the target). In this case, creates an empty
16
+ * decisionList to ensure the target type exists.
17
+ *
18
+ * Similar to handleEmptyContainerEdgeCase in wrapMixedContentStep, but specifically for
19
+ * multi-to-decisionList transformations where blockquotes break out.
20
+ *
21
+ * @param result - The current result nodes after processing
22
+ * @param hasCreatedDecisionList - Whether a decisionList was already created during processing
23
+ * @param targetNodeTypeName - The target node type name
24
+ * @param schema - The schema
25
+ * @returns The result nodes with an empty decisionList prepended if needed, or the original result
26
+ */
27
+ var handleEmptyDecisionListEdgeCase = function handleEmptyDecisionListEdgeCase(result, hasCreatedDecisionList, targetNodeTypeName, schema) {
28
+ // Only apply this edge case for decisionList target
29
+ if (targetNodeTypeName !== 'decisionList') {
30
+ return result;
31
+ }
32
+
33
+ // If no decisionList was created but we have nodes in result, all content broke out
34
+ var allContentBrokeOut = !hasCreatedDecisionList && result.length > 0;
35
+ if (!allContentBrokeOut) {
36
+ return result;
37
+ }
38
+
39
+ // Create an empty decisionList
40
+ var decisionListType = schema.nodes.decisionList;
41
+ var decisionItemType = schema.nodes.decisionItem;
42
+ if (decisionListType && decisionItemType) {
43
+ var emptyDecisionItem = decisionItemType.createAndFill();
44
+ if (emptyDecisionItem) {
45
+ var emptyDecisionList = decisionListType.createAndFill({}, [emptyDecisionItem]);
46
+ if (emptyDecisionList) {
47
+ return [emptyDecisionList].concat((0, _toConsumableArray2.default)(result));
48
+ }
49
+ }
50
+ }
51
+ return result;
52
+ };
13
53
  var convertEachNodeStep = exports.convertEachNodeStep = function convertEachNodeStep(nodes, context) {
14
54
  var schema = context.schema,
15
55
  targetNodeTypeName = context.targetNodeTypeName,
@@ -18,12 +58,19 @@ var convertEachNodeStep = exports.convertEachNodeStep = function convertEachNode
18
58
  if (!targetNodeType) {
19
59
  return nodes;
20
60
  }
61
+ var blockquoteType = schema.nodes.blockquote;
21
62
  var resultNodes = [];
63
+ var hasCreatedDecisionList = false;
22
64
  var _iterator = _createForOfIteratorHelper(nodes),
23
65
  _step;
24
66
  try {
25
67
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
26
68
  var node = _step.value;
69
+ // Edge case: blockquotes should break out when transforming to decisionList
70
+ if (targetNodeTypeName === 'decisionList' && blockquoteType && node.type === blockquoteType) {
71
+ resultNodes.push(node);
72
+ continue;
73
+ }
27
74
  var transformedNodes = (0, _transform.convertNodesToTargetType)({
28
75
  sourceNodes: [node],
29
76
  targetNodeType: targetNodeType,
@@ -33,14 +80,24 @@ var convertEachNodeStep = exports.convertEachNodeStep = function convertEachNode
33
80
  });
34
81
  if (transformedNodes.length > 0) {
35
82
  resultNodes.push.apply(resultNodes, (0, _toConsumableArray2.default)(transformedNodes));
83
+ // Track if we created a decisionList
84
+
85
+ if (targetNodeTypeName === 'decisionList' && transformedNodes.some(function (n) {
86
+ return n.type === targetNodeType;
87
+ })) {
88
+ hasCreatedDecisionList = true;
89
+ }
36
90
  } else {
37
91
  resultNodes.push(node);
38
92
  }
39
93
  }
94
+
95
+ // Handle edge case: if no decisionList was created, create an empty one
40
96
  } catch (err) {
41
97
  _iterator.e(err);
42
98
  } finally {
43
99
  _iterator.f();
44
100
  }
45
- return resultNodes;
101
+ var finalResult = handleEmptyDecisionListEdgeCase(resultNodes, hasCreatedDecisionList, targetNodeTypeName, schema);
102
+ return finalResult;
46
103
  };
@@ -5,239 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isTransformDisabledBasedOnStepsConfig = exports.convertNodesToTargetType = void 0;
7
7
  var _utils = require("../transform-node-utils/utils");
8
- var _flattenStep = require("./flattenStep");
9
- var _applyTargetTextTypeStep = require("./steps/applyTargetTextTypeStep");
10
- var _convertEachNodeStep = require("./steps/convertEachNodeStep");
11
- var _decisionListToListStep = require("./steps/decisionListToListStep");
12
- var _flattenListStep = require("./steps/flattenListStep");
13
- var _listToDecisionListStep = require("./steps/listToDecisionListStep");
14
- var _listToListStep = require("./steps/listToListStep");
15
- var _mergeNeighbourListsStep = require("./steps/mergeNeighbourListsStep");
16
- var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
17
- var _unwrapListStep = require("./steps/unwrapListStep");
18
- var _wrapBlockquoteToDecisionListStep = require("./steps/wrapBlockquoteToDecisionListStep");
19
- var _wrapMixedContentStep = require("./steps/wrapMixedContentStep");
8
+ var _TRANSFORMATION_MATRIX = require("./TRANSFORMATION_MATRIX");
20
9
  var _types = require("./types");
21
- var _unwrapExpandStep = require("./unwrapExpandStep");
22
- var _unwrapStep = require("./unwrapStep");
23
- var _wrapIntoListStep = require("./wrapIntoListStep");
24
- var _wrapStep = require("./wrapStep");
25
- // Transform steps for combinations of node categories (block/container/list/text)
26
- var TRANSFORM_STEPS = {
27
- atomic: {
28
- atomic: undefined,
29
- container: [_wrapStep.wrapStep],
30
- list: [_wrapIntoListStep.wrapIntoListStep],
31
- text: undefined,
32
- multi: undefined
33
- },
34
- container: {
35
- atomic: undefined,
36
- container: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
37
- list: undefined,
38
- text: [_unwrapStep.unwrapStep],
39
- multi: undefined
40
- },
41
- list: {
42
- atomic: undefined,
43
- container: [_wrapStep.wrapStep],
44
- list: [_listToListStep.listToListStep],
45
- text: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
46
- multi: undefined
47
- },
48
- text: {
49
- atomic: undefined,
50
- container: [_wrapMixedContentStep.wrapMixedContentStep],
51
- list: [_wrapIntoListStep.wrapIntoListStep],
52
- text: [_flattenStep.flattenStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
53
- multi: undefined
54
- },
55
- multi: {
56
- atomic: undefined,
57
- container: [_wrapMixedContentStep.wrapMixedContentStep],
58
- list: [_convertEachNodeStep.convertEachNodeStep, _mergeNeighbourListsStep.mergeNeighbourListsStep],
59
- text: [_convertEachNodeStep.convertEachNodeStep],
60
- multi: undefined
61
- }
62
- };
63
-
64
- // Transform steps for specific pairs of node types that cannot be processed
65
- // using generic rules/steps from TRANSFORM_STEPS.
66
- // Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
67
- var TRANSFORM_STEPS_OVERRIDE = {
68
- paragraph: {
69
- paragraph: null
70
- },
71
- heading: {},
72
- panel: {
73
- panel: null,
74
- layoutSection: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
75
- codeBlock: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
76
- blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
77
- taskList: null,
78
- bulletList: null,
79
- orderedList: null,
80
- heading: null
81
- },
82
- expand: {
83
- expand: null,
84
- panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
85
- blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
86
- layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
87
- paragraph: [_unwrapExpandStep.unwrapExpandStep],
88
- codeBlock: null,
89
- heading: null
90
- },
91
- nestedExpand: {
92
- expand: null,
93
- nestedExpand: null,
94
- panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
95
- blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
96
- paragraph: [_unwrapExpandStep.unwrapExpandStep],
97
- codeBlock: null,
98
- heading: null
99
- },
100
- blockquote: {
101
- blockquote: null,
102
- expand: [_wrapStep.wrapStep],
103
- nestedExpand: [_wrapStep.wrapStep],
104
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
105
- codeBlock: null,
106
- decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep],
107
- paragraph: [_unwrapStep.unwrapStep],
108
- heading: [_unwrapStep.unwrapStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
109
- },
110
- layoutSection: {
111
- layoutSection: null,
112
- blockquote: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
113
- expand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
114
- panel: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
115
- codeBlock: null,
116
- paragraph: [_unwrapLayoutStep.unwrapLayoutStep],
117
- heading: null
118
- },
119
- codeBlock: {
120
- codeBlock: null,
121
- blockquote: [_wrapStep.wrapStep],
122
- expand: [_wrapStep.wrapStep],
123
- nestedExpand: [_wrapStep.wrapStep],
124
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
125
- panel: [_wrapStep.wrapStep],
126
- paragraph: [_applyTargetTextTypeStep.applyTargetTextTypeStep],
127
- heading: null
128
- },
129
- bulletList: {
130
- bulletList: null,
131
- codeBlock: null,
132
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
133
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
134
- heading: null
135
- },
136
- orderedList: {
137
- orderedList: null,
138
- codeBlock: null,
139
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
140
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
141
- heading: null
142
- },
143
- taskList: {
144
- blockquote: null,
145
- codeBlock: null,
146
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
147
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
148
- heading: null,
149
- taskList: null
150
- },
151
- table: {
152
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
153
- blockquote: null,
154
- panel: null,
155
- codeBlock: null,
156
- orderedList: null,
157
- bulletList: null,
158
- taskList: null,
159
- decisionList: null
160
- },
161
- mediaSingle: {
162
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
163
- codeBlock: null,
164
- decisionList: null,
165
- taskList: null
166
- },
167
- mediaGroup: {
168
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
169
- codeBlock: null,
170
- decisionList: null,
171
- bulletList: null,
172
- orderedList: null,
173
- taskList: null
174
- },
175
- decisionList: {
176
- decisionList: null,
177
- bulletList: [_decisionListToListStep.decisionListToListStep],
178
- orderedList: [_decisionListToListStep.decisionListToListStep],
179
- taskList: [_decisionListToListStep.decisionListToListStep],
180
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
181
- blockquote: [_unwrapListStep.unwrapListStep, _wrapStep.wrapStep],
182
- codeBlock: [_unwrapListStep.unwrapListStep, _wrapMixedContentStep.wrapMixedContentStep]
183
- },
184
- blockCard: {
185
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
186
- blockquote: null,
187
- codeBlock: null,
188
- orderedList: null,
189
- bulletList: null,
190
- taskList: null,
191
- decisionList: null
192
- },
193
- embedCard: {
194
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
195
- blockquote: null,
196
- panel: null,
197
- codeBlock: null,
198
- orderedList: null,
199
- bulletList: null,
200
- taskList: null,
201
- decisionList: null
202
- },
203
- extension: {
204
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
205
- codeBlock: null,
206
- decisionList: null,
207
- taskList: null,
208
- orderedList: null,
209
- bulletList: null
210
- },
211
- bodiedExtension: {
212
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
213
- blockquote: null,
214
- expand: null,
215
- panel: null,
216
- codeBlock: null,
217
- orderedList: null,
218
- bulletList: null,
219
- taskList: null,
220
- decisionList: null
221
- },
222
- multi: {
223
- heading: [_applyTargetTextTypeStep.applyTargetTextTypeStep]
224
- // Similar to heading, all structures are kept as is
225
- // EG: transformed: other lists, paragarph, headings
226
- // eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
227
- // decisionList: [],
228
- }
229
- };
230
- var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
231
- var _TRANSFORM_STEPS_OVER;
232
- var fromCategory = _types.NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
233
- var toCategory = _types.NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
234
- var overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
235
- if (overrideSteps === null) {
236
- return null;
237
- }
238
- var steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
239
- return steps;
240
- };
241
10
  /**
242
11
  * Convert a list of nodes to a target node type.
243
12
  * If no steps are found, the source nodes are returned unchanged.
@@ -270,7 +39,7 @@ var convertNodesToTargetType = exports.convertNodesToTargetType = function conve
270
39
  if (!selectedNodeTypeName || !targetNodeTypeName) {
271
40
  return sourceNodes;
272
41
  }
273
- var steps = getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName);
42
+ var steps = _TRANSFORMATION_MATRIX.TRANSFORMATION_MATRIX[selectedNodeTypeName][targetNodeTypeName];
274
43
  var context = {
275
44
  // sourceNode is incorrect now - what to do here?
276
45
  fromNode: sourceNode,
@@ -286,9 +55,6 @@ var convertNodesToTargetType = exports.convertNodesToTargetType = function conve
286
55
  }, sourceNodes);
287
56
  };
288
57
  var isTransformDisabledBasedOnStepsConfig = exports.isTransformDisabledBasedOnStepsConfig = function isTransformDisabledBasedOnStepsConfig(selectedNodeType, targetNodeType) {
289
- var steps = getTransformStepsForNodeTypes(selectedNodeType, targetNodeType);
290
- if (!steps || steps.length === 0) {
291
- return true;
292
- }
293
- return false;
58
+ var steps = _TRANSFORMATION_MATRIX.TRANSFORMATION_MATRIX[selectedNodeType][targetNodeType];
59
+ return !steps || steps.length === 0;
294
60
  };
@@ -19,6 +19,8 @@ var _moveDown = require("./move-down");
19
19
  var _moveUp = require("./move-up");
20
20
  var _suggestedItemsMenuSection = require("./suggested-items-menu-section");
21
21
  var _suggestedMenuItems = require("./suggested-menu-items");
22
+ var _createMenuItemsMap = require("./utils/createMenuItemsMap");
23
+ var _getSuggestedItemsFromSelection = require("./utils/getSuggestedItemsFromSelection");
22
24
  var getMoveUpMoveDownMenuComponents = function getMoveUpMoveDownMenuComponents(api) {
23
25
  return [{
24
26
  type: 'block-menu-item',
@@ -95,6 +97,16 @@ var getTurnIntoMenuComponents = function getTurnIntoMenuComponents(api) {
95
97
  return /*#__PURE__*/_react.default.createElement(_suggestedMenuItems.SuggestedMenuItems, {
96
98
  api: api
97
99
  });
100
+ },
101
+ isHidden: function isHidden() {
102
+ var _api$blockMenu, _api$selection, _api$blockControls;
103
+ var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
104
+ var menuItemsMap = (0, _createMenuItemsMap.createMenuItemsMap)(blockMenuComponents);
105
+ 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;
106
+ 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;
107
+ var currentSelection = preservedSelection || selection;
108
+ var suggestedItems = (0, _getSuggestedItemsFromSelection.getSuggestedItemsFromSelection)(menuItemsMap, currentSelection);
109
+ return suggestedItems.length === 0;
98
110
  }
99
111
  }, {
100
112
  type: 'block-menu-section',
@@ -15,15 +15,15 @@ var BlockMenuComponent = exports.BlockMenuComponent = function BlockMenuComponen
15
15
  var registeredComponent = _ref.registeredComponent,
16
16
  childrenMap = _ref.childrenMap,
17
17
  fallbacks = _ref.fallbacks;
18
+ if (!(0, _utils.willComponentRender)(registeredComponent, childrenMap)) {
19
+ return null;
20
+ }
18
21
  if (registeredComponent.type === 'block-menu-item') {
19
22
  var ItemComponent = registeredComponent.component || fallbacks['block-menu-item'];
20
23
  return /*#__PURE__*/_react.default.createElement(ItemComponent, {
21
24
  key: registeredComponent.key
22
25
  });
23
26
  }
24
- if (!(0, _utils.willComponentRender)(registeredComponent, childrenMap)) {
25
- return null;
26
- }
27
27
  var ParentComponent = registeredComponent.component || fallbacks[registeredComponent.type];
28
28
  var childrenMapKey = (0, _utils.getChildrenMapKey)(registeredComponent.key, registeredComponent.type);
29
29
  var registeredComponents = childrenMap.get(childrenMapKey);
@@ -106,21 +106,18 @@ var buildChildrenMap = exports.buildChildrenMap = function buildChildrenMap(comp
106
106
  * Determines whether a component will render based on its type and children
107
107
  *
108
108
  * Rules:
109
- * - An item will not render if has a component that returns null
110
- * - A nested menu will render if it has at least one registered child component
109
+ * - An item will not render if it has isHidden that returns true OR if its component returns null (fallback)
110
+ * - A nested menu will render if at least one section, that has at least one registered child
111
111
  * - A section will render if it has at least one registered child component that will render
112
112
  *
113
- * NOTE: This requires invoking each item's component function to check for null return
114
113
  */
115
114
  var _willComponentRender = exports.willComponentRender = function willComponentRender(registeredComponent, childrenMap) {
116
115
  if (registeredComponent.type === 'block-menu-item') {
117
- return registeredComponent.component ? registeredComponent.component() !== null : true;
116
+ var _registeredComponent$;
117
+ return !(registeredComponent !== null && registeredComponent !== void 0 && (_registeredComponent$ = registeredComponent.isHidden) !== null && _registeredComponent$ !== void 0 && _registeredComponent$.call(registeredComponent));
118
118
  }
119
119
  var childrenMapKey = getChildrenMapKey(registeredComponent.key, registeredComponent.type);
120
120
  var registeredComponents = childrenMap.get(childrenMapKey) || [];
121
- if (registeredComponent.type === 'block-menu-nested') {
122
- return registeredComponents.length > 0;
123
- }
124
121
  return registeredComponents.some(function (childComponent) {
125
122
  return _willComponentRender(childComponent, childrenMap);
126
123
  });