@atlaskit/editor-plugin-block-menu 5.2.19 → 5.2.21

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 (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/blockMenuPlugin.js +17 -2
  3. package/dist/cjs/editor-actions/isTrasformToTargetDisabled.js +114 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  5. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +2 -16
  6. package/dist/cjs/editor-commands/transform-node-utils/transform.js +99 -29
  7. package/dist/cjs/editor-commands/transform-node-utils/utils.js +16 -1
  8. package/dist/cjs/editor-commands/transform-node-utils/wrapIntoListStep.js +10 -2
  9. package/dist/es2019/blockMenuPlugin.js +17 -2
  10. package/dist/es2019/editor-actions/isTrasformToTargetDisabled.js +110 -0
  11. package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  12. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +1 -15
  13. package/dist/es2019/editor-commands/transform-node-utils/transform.js +98 -28
  14. package/dist/es2019/editor-commands/transform-node-utils/utils.js +15 -0
  15. package/dist/es2019/editor-commands/transform-node-utils/wrapIntoListStep.js +6 -2
  16. package/dist/esm/blockMenuPlugin.js +17 -2
  17. package/dist/esm/editor-actions/isTrasformToTargetDisabled.js +108 -0
  18. package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  19. package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +1 -15
  20. package/dist/esm/editor-commands/transform-node-utils/transform.js +98 -28
  21. package/dist/esm/editor-commands/transform-node-utils/utils.js +15 -0
  22. package/dist/esm/editor-commands/transform-node-utils/wrapIntoListStep.js +10 -2
  23. package/dist/types/blockMenuPluginType.d.ts +1 -0
  24. package/dist/types/editor-actions/isTrasformToTargetDisabled.d.ts +11 -0
  25. package/dist/types/editor-commands/transform-node-utils/transform.d.ts +2 -0
  26. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +6 -0
  27. package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -0
  28. package/dist/types-ts4.5/editor-actions/isTrasformToTargetDisabled.d.ts +11 -0
  29. package/dist/types-ts4.5/editor-commands/transform-node-utils/transform.d.ts +2 -0
  30. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +6 -0
  31. package/package.json +4 -4
  32. package/dist/cjs/editor-commands/transform-node-utils/stubStep.js +0 -9
  33. package/dist/es2019/editor-commands/transform-node-utils/stubStep.js +0 -3
  34. package/dist/esm/editor-commands/transform-node-utils/stubStep.js +0 -3
  35. package/dist/types/editor-commands/transform-node-utils/stubStep.d.ts +0 -2
  36. package/dist/types-ts4.5/editor-commands/transform-node-utils/stubStep.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.2.21
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b5d004bf834f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b5d004bf834f8) -
8
+ [ux] Adds block menu action to check if 'Turn into' item should be rendered or not.
9
+ - Updated dependencies
10
+
11
+ ## 5.2.20
12
+
13
+ ### Patch Changes
14
+
15
+ - [`65f1df43f39d7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/65f1df43f39d7) -
16
+ Add heading transform
17
+ - Updated dependencies
18
+
3
19
  ## 5.2.19
4
20
 
5
21
  ### Patch Changes
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.blockMenuPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _editorActions = require("./editor-actions");
10
+ var _isTrasformToTargetDisabled = require("./editor-actions/isTrasformToTargetDisabled");
10
11
  var _formatNode2 = require("./editor-commands/formatNode");
11
12
  var _transformNode2 = require("./editor-commands/transformNode");
12
13
  var _main = require("./pm-plugins/main");
@@ -36,6 +37,20 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
36
37
  },
37
38
  getBlockMenuComponents: function getBlockMenuComponents() {
38
39
  return registry.components;
40
+ },
41
+ isTransformOptionDisabled: function isTransformOptionDisabled(optionNodeTypeName, optionNodeTypeAttrs) {
42
+ var _api$blockControls, _api$selection;
43
+ 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;
44
+ var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
45
+ var currentSelection = preservedSelection || selection;
46
+ if (!currentSelection) {
47
+ return true;
48
+ }
49
+ return (0, _isTrasformToTargetDisabled.isTrasformToTargetDisabled)({
50
+ selection: currentSelection,
51
+ targetNodeTypeName: optionNodeTypeName,
52
+ targetNodeTypeAttrs: optionNodeTypeAttrs
53
+ });
39
54
  }
40
55
  },
41
56
  commands: {
@@ -47,7 +62,7 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
47
62
  }
48
63
  },
49
64
  getSharedState: function getSharedState(editorState) {
50
- var _api$blockControls, _pluginState$showFlag;
65
+ var _api$blockControls2, _pluginState$showFlag;
51
66
  if (!editorState) {
52
67
  return {
53
68
  currentSelectedNodeName: undefined,
@@ -56,7 +71,7 @@ var blockMenuPlugin = exports.blockMenuPlugin = function blockMenuPlugin(_ref) {
56
71
  }
57
72
 
58
73
  // Get the menuTriggerBy from blockControls plugin if available
59
- var currentSelectedNodeName = 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.menuTriggerBy;
74
+ var currentSelectedNodeName = api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.menuTriggerBy;
60
75
 
61
76
  // Get the showFlag from plugin state
62
77
  var pluginState = _main.blockMenuPluginKey.getState(editorState);
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isTrasformToTargetDisabled = exports.canParentContainNodeType = void 0;
7
+ var _selection = require("@atlaskit/editor-common/selection");
8
+ var _model = require("@atlaskit/editor-prosemirror/model");
9
+ var _transform = require("../editor-commands/transform-node-utils/transform");
10
+ var _types = require("../editor-commands/transform-node-utils/types");
11
+ var _utils = require("../editor-commands/transform-node-utils/utils");
12
+ var canParentContainNodeType = exports.canParentContainNodeType = function canParentContainNodeType(schema, parentNode, nodeTypeName, nodeTypeAttrs) {
13
+ var adjustedNodeTypeName = (0, _utils.getTargetNodeTypeNameInContext)(nodeTypeName, true);
14
+ if (!adjustedNodeTypeName) {
15
+ return false;
16
+ }
17
+ var nodeType = schema.nodes[adjustedNodeTypeName];
18
+ return parentNode.type.validContent(_model.Fragment.from(nodeType.createAndFill(nodeTypeAttrs)));
19
+ };
20
+ var isHeadingToHeadingTransformEnabled = function isHeadingToHeadingTransformEnabled(selectedNode, targetNodeTypeAttrs) {
21
+ var _selectedNode$attrs;
22
+ var selectedLevel = (_selectedNode$attrs = selectedNode.attrs) === null || _selectedNode$attrs === void 0 ? void 0 : _selectedNode$attrs.level;
23
+ var targetLevel = targetNodeTypeAttrs === null || targetNodeTypeAttrs === void 0 ? void 0 : targetNodeTypeAttrs.level;
24
+ if (selectedLevel === undefined || targetLevel === undefined) {
25
+ return false;
26
+ }
27
+ return selectedLevel !== targetLevel;
28
+ };
29
+ var isTransformEnabledForNode = function isTransformEnabledForNode(node, targetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema) {
30
+ var selectedNodeTypeName = (0, _types.toNodeTypeValue)(node.type.name);
31
+ if (!selectedNodeTypeName) {
32
+ return false;
33
+ }
34
+ var isDisabledByStepsConfig = (0, _transform.isTransformDisabledBasedOnStepsConfig)(selectedNodeTypeName, targetNodeTypeName);
35
+ if (isDisabledByStepsConfig) {
36
+ return false;
37
+ }
38
+ if (selectedNodeTypeName === 'heading' && targetNodeTypeName === 'heading') {
39
+ return isHeadingToHeadingTransformEnabled(node, targetNodeTypeAttrs);
40
+ }
41
+ if (isNested && !canParentContainNodeType(schema, parent, targetNodeTypeName, targetNodeTypeAttrs)) {
42
+ return false;
43
+ }
44
+ return true;
45
+ };
46
+ var isTrasformToTargetDisabled = exports.isTrasformToTargetDisabled = function isTrasformToTargetDisabled(_ref) {
47
+ var selection = _ref.selection,
48
+ targetNodeTypeName = _ref.targetNodeTypeName,
49
+ targetNodeTypeAttrs = _ref.targetNodeTypeAttrs;
50
+ var _expandSelectionToBlo = (0, _selection.expandSelectionToBlockRange)(selection),
51
+ range = _expandSelectionToBlo.range;
52
+ if (!range) {
53
+ return false;
54
+ }
55
+ var selectedNodes = (0, _utils.getBlockNodesInRange)(range);
56
+ var parent = range.parent;
57
+ var isNested = range.depth >= 1;
58
+ var schema = selection.$from.doc.type.schema;
59
+ var supportedTargetNodeTypeName = (0, _types.toNodeTypeValue)(targetNodeTypeName);
60
+ if (!supportedTargetNodeTypeName) {
61
+ return true;
62
+ }
63
+ var isEnabledForAnyNode = selectedNodes.some(function (node) {
64
+ return isTransformEnabledForNode(node, supportedTargetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema);
65
+ });
66
+ return !isEnabledForAnyNode;
67
+ };
68
+
69
+ // export const isTrasformToTargetDisabled = ({
70
+ // selection,
71
+ // targetNodeTypeName,
72
+ // targetNodeTypeAttrs,
73
+ // }: TransformDisabledArgs) => {
74
+ // const { range } = expandSelectionToBlockRange(selection);
75
+ // if (!range) {
76
+ // return false;
77
+ // }
78
+
79
+ // const selectedNodes = getBlockNodesInRange(range);
80
+ // const parent = range.parent;
81
+ // const isNested = range.depth >= 1;
82
+
83
+ // const { schema } = selection.$from.doc.type;
84
+
85
+ // const isTransformEnabledForAnySelectedNode = selectedNodes.some((node) => {
86
+ // const selectedNodeTypeName = toNodeTypeValue(node.type.name);
87
+ // const supportedTargetNodeTypeName = toNodeTypeValue(targetNodeTypeName);
88
+ // if (!selectedNodeTypeName || !supportedTargetNodeTypeName) {
89
+ // return false;
90
+ // }
91
+
92
+ // if (isTransformDisabledBasedOnStepsConfig(selectedNodeTypeName, supportedTargetNodeTypeName)) {
93
+ // if (selectedNodeTypeName === 'heading' && supportedTargetNodeTypeName === 'heading') {
94
+ // return isHeadingToHeadingTransformDisabled(node, targetNodeTypeAttrs);
95
+ // }
96
+ // return false;
97
+ // }
98
+
99
+ // if (
100
+ // isNested &&
101
+ // !canParentContainNodeType(schema, parent, supportedTargetNodeTypeName, targetNodeTypeAttrs)
102
+ // ) {
103
+ // return false;
104
+ // }
105
+
106
+ // return true;
107
+ // });
108
+
109
+ // if (isTransformEnabledForAnySelectedNode) {
110
+ // return false;
111
+ // }
112
+
113
+ // return true;
114
+ // };
@@ -45,7 +45,7 @@ var listToDecisionListStep = exports.listToDecisionListStep = function listToDec
45
45
  if (child.type === paragraphType) {
46
46
  // paragraph may contain hard breaks etc.
47
47
  itemContent.push.apply(itemContent, (0, _toConsumableArray2.default)(child.children));
48
- } else if (child.isText) {
48
+ } else if (child.isText || child.isInline) {
49
49
  itemContent.push(child);
50
50
  } else if (!(0, _nodeChecks.isListWithIndentation)(child.type.name, schema)) {
51
51
  unsupportedContent.push(child);
@@ -8,6 +8,7 @@ exports.wrapMixedContentStep = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _model = require("@atlaskit/editor-prosemirror/model");
10
10
  var _types = require("../types");
11
+ var _utils = require("../utils");
11
12
  /**
12
13
  * Determines if a node is a text node (heading or paragraph).
13
14
  * Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
@@ -17,21 +18,6 @@ var isTextNode = function isTextNode(node) {
17
18
  return category === 'text';
18
19
  };
19
20
 
20
- /**
21
- * Converts a text node (heading, paragraph) to a paragraph preserving its inline content.
22
- * This is used when a text node can't be wrapped directly in the target container
23
- * (e.g., heading can't go in blockquote, so it becomes a paragraph).
24
- */
25
- var convertTextNodeToParagraph = function convertTextNodeToParagraph(node, schema) {
26
- var _schema$nodes$paragra;
27
- // If it's already a paragraph, return as-is
28
- if (node.type.name === 'paragraph') {
29
- return node;
30
- }
31
- // Convert heading (or other text node) to paragraph with same inline content
32
- return (_schema$nodes$paragra = schema.nodes.paragraph.createAndFill({}, node.content)) !== null && _schema$nodes$paragra !== void 0 ? _schema$nodes$paragra : null;
33
- };
34
-
35
21
  /**
36
22
  * Determines if a node can be wrapped in the target container type.
37
23
  * Uses the schema's validContent to check if the target container can hold this node.
@@ -134,7 +120,7 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
134
120
  } else if (isTextNode(node)) {
135
121
  // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
136
122
  // Example: heading can't go in blockquote, so convert to paragraph with same content
137
- var paragraph = convertTextNodeToParagraph(node, schema);
123
+ var paragraph = (0, _utils.convertTextNodeToParagraph)(node, schema);
138
124
  if (paragraph) {
139
125
  currentContainerContent.push(paragraph);
140
126
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getOutputNodes = void 0;
6
+ exports.isTransformDisabledBasedOnStepsConfig = exports.getOutputNodes = void 0;
7
7
  var _utils = require("../transform-node-utils/utils");
8
8
  var _flattenStep = require("./flattenStep");
9
9
  var _applyTargetTextTypeStep = require("./steps/applyTargetTextTypeStep");
@@ -16,7 +16,6 @@ var _unwrapListStep = require("./steps/unwrapListStep");
16
16
  var _wrapBlockquoteToDecisionListStep = require("./steps/wrapBlockquoteToDecisionListStep");
17
17
  var _wrapMixedContentStep = require("./steps/wrapMixedContentStep");
18
18
  var _wrapTextToCodeblock = require("./steps/wrapTextToCodeblock");
19
- var _stubStep = require("./stubStep");
20
19
  var _types = require("./types");
21
20
  var _unwrapExpandStep = require("./unwrapExpandStep");
22
21
  var _unwrapStep = require("./unwrapStep");
@@ -45,7 +44,7 @@ var TRANSFORM_STEPS = {
45
44
  },
46
45
  text: {
47
46
  atomic: undefined,
48
- container: [_wrapStep.wrapStep],
47
+ container: [_wrapMixedContentStep.wrapMixedContentStep],
49
48
  list: [_wrapIntoListStep.wrapIntoListStep],
50
49
  text: [_flattenStep.flattenStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
51
50
  }
@@ -53,102 +52,166 @@ var TRANSFORM_STEPS = {
53
52
 
54
53
  // Transform steps for specific pairs of node types that cannot be processed
55
54
  // using generic rules/steps from TRANSFORM_STEPS.
55
+ // Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
56
56
  var TRANSFORM_STEPS_OVERRIDE = {
57
57
  paragraph: {
58
+ paragraph: null,
59
+ codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
60
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
61
+ },
62
+ heading: {
58
63
  codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
59
64
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
60
65
  },
61
66
  panel: {
67
+ panel: null,
62
68
  layoutSection: [_unwrapStep.unwrapStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
63
69
  codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
64
- blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep]
70
+ blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
71
+ taskList: null,
72
+ bulletList: null,
73
+ orderedList: null,
74
+ heading: null
65
75
  },
66
76
  expand: {
77
+ expand: null,
67
78
  panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
68
79
  blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
69
80
  layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
70
81
  paragraph: [_unwrapExpandStep.unwrapExpandStep],
71
- codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
82
+ codeBlock: null,
83
+ heading: null
72
84
  },
73
85
  nestedExpand: {
86
+ expand: null,
87
+ nestedExpand: null,
74
88
  panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
75
89
  blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
76
90
  paragraph: [_unwrapExpandStep.unwrapExpandStep],
77
- codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
91
+ codeBlock: null,
92
+ heading: null
78
93
  },
79
94
  blockquote: {
95
+ blockquote: null,
80
96
  expand: [_wrapStep.wrapStep],
81
97
  nestedExpand: [_wrapStep.wrapStep],
82
98
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
83
- codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
99
+ codeBlock: null,
84
100
  decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
85
101
  },
86
102
  layoutSection: {
103
+ layoutSection: null,
87
104
  blockquote: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
88
105
  expand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
89
106
  panel: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
90
- codeBlock: [_unwrapLayoutStep.unwrapLayoutStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
91
- paragraph: [_unwrapLayoutStep.unwrapLayoutStep]
107
+ codeBlock: null,
108
+ paragraph: [_unwrapLayoutStep.unwrapLayoutStep],
109
+ heading: null
92
110
  },
93
111
  codeBlock: {
112
+ codeBlock: null,
94
113
  blockquote: [_wrapStep.wrapStep],
95
114
  expand: [_wrapStep.wrapStep],
96
115
  nestedExpand: [_wrapStep.wrapStep],
97
116
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
98
- panel: [_wrapStep.wrapStep]
117
+ panel: [_wrapStep.wrapStep],
118
+ heading: null
99
119
  },
100
120
  bulletList: {
101
- // Text transformations currently not in scope > options will be disabled > stubbing in case
102
- codeBlock: [_stubStep.stubStep],
121
+ bulletList: null,
122
+ codeBlock: null,
103
123
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
104
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
124
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
125
+ heading: null
105
126
  },
106
127
  orderedList: {
107
- // Text transformations currently not in scope > options will be disabled > stubbing in case
108
- codeBlock: [_stubStep.stubStep],
128
+ orderedList: null,
129
+ codeBlock: null,
109
130
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
110
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
131
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
132
+ heading: null
111
133
  },
112
134
  taskList: {
113
- // Text transformations currently not in scope > options will be disabled > stubbing in case
114
- blockquote: [_stubStep.stubStep],
115
- codeBlock: [_stubStep.stubStep],
135
+ blockquote: null,
136
+ codeBlock: null,
116
137
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
117
- decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
138
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
139
+ heading: null,
140
+ taskList: null
118
141
  },
119
142
  table: {
120
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
143
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
144
+ blockquote: null,
145
+ panel: null,
146
+ codeBlock: null,
147
+ orderedList: null,
148
+ bulletList: null,
149
+ taskList: null,
150
+ decisionList: null
121
151
  },
122
152
  mediaSingle: {
123
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
153
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
154
+ codeBlock: null,
155
+ decisionList: null,
156
+ taskList: null
124
157
  },
125
158
  mediaGroup: {
126
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
159
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
160
+ codeBlock: null
127
161
  },
128
162
  decisionList: {
163
+ decisionList: null,
129
164
  bulletList: [_decisionListToListStep.decisionListToListStep],
130
165
  orderedList: [_decisionListToListStep.decisionListToListStep],
131
166
  taskList: [_decisionListToListStep.decisionListToListStep],
132
167
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
133
168
  },
134
169
  blockCard: {
135
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
170
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
171
+ blockquote: null,
172
+ codeBlock: null,
173
+ orderedList: null,
174
+ bulletList: null,
175
+ taskList: null,
176
+ decisionList: null
136
177
  },
137
178
  embedCard: {
138
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
179
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
180
+ blockquote: null,
181
+ panel: null,
182
+ codeBlock: null,
183
+ orderedList: null,
184
+ bulletList: null,
185
+ taskList: null,
186
+ decisionList: null
139
187
  },
140
188
  extension: {
141
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
189
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
190
+ codeBlock: null,
191
+ decisionList: null,
192
+ taskList: null
142
193
  },
143
194
  bodiedExtension: {
144
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
195
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
196
+ blockquote: null,
197
+ expand: null,
198
+ panel: null,
199
+ codeBlock: null,
200
+ orderedList: null,
201
+ bulletList: null,
202
+ taskList: null,
203
+ decisionList: null
145
204
  }
146
205
  };
147
206
  var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
148
- var _TRANSFORM_STEPS_OVER, _TRANSFORM_STEPS_OVER2;
207
+ var _TRANSFORM_STEPS_OVER;
149
208
  var fromCategory = _types.NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
150
209
  var toCategory = _types.NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
151
- var steps = (_TRANSFORM_STEPS_OVER = (_TRANSFORM_STEPS_OVER2 = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER2 === void 0 ? void 0 : _TRANSFORM_STEPS_OVER2[targetNodeTypeName]) !== null && _TRANSFORM_STEPS_OVER !== void 0 ? _TRANSFORM_STEPS_OVER : TRANSFORM_STEPS[fromCategory][toCategory];
210
+ var overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
211
+ if (overrideSteps === null) {
212
+ return null;
213
+ }
214
+ var steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
152
215
  return steps;
153
216
  };
154
217
  // Note: Currently works only for single node in the selection
@@ -179,4 +242,11 @@ var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
179
242
  return steps.reduce(function (nodes, step) {
180
243
  return step(nodes, context);
181
244
  }, nodesToReplace);
245
+ };
246
+ var isTransformDisabledBasedOnStepsConfig = exports.isTransformDisabledBasedOnStepsConfig = function isTransformDisabledBasedOnStepsConfig(selectedNodeType, targetNodeType) {
247
+ var steps = getTransformStepsForNodeTypes(selectedNodeType, targetNodeType);
248
+ if (!steps || steps.length === 0) {
249
+ return true;
250
+ }
251
+ return false;
182
252
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.createTextContent = exports.convertNestedExpandToExpand = exports.convertExpandToNestedExpand = void 0;
6
+ exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.createTextContent = exports.convertTextNodeToParagraph = exports.convertNestedExpandToExpand = exports.convertExpandToNestedExpand = void 0;
7
7
  var _state = require("@atlaskit/editor-prosemirror/state");
8
8
  var _utils = require("@atlaskit/editor-prosemirror/utils");
9
9
  var _editorTables = require("@atlaskit/editor-tables");
@@ -87,6 +87,21 @@ var convertExpandToNestedExpand = exports.convertExpandToNestedExpand = function
87
87
  title: ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.title) || ''
88
88
  }, node.content);
89
89
  };
90
+
91
+ /**
92
+ * Converts a text node (heading, paragraph) to a paragraph preserving its inline content.
93
+ * This is used when a text node can't be wrapped directly in the target container
94
+ * (e.g., heading can't go in blockquote, so it becomes a paragraph).
95
+ */
96
+ var convertTextNodeToParagraph = exports.convertTextNodeToParagraph = function convertTextNodeToParagraph(node, schema) {
97
+ var _schema$nodes$paragra;
98
+ // If it's already a paragraph, return as-is
99
+ if (node.type.name === 'paragraph') {
100
+ return node;
101
+ }
102
+ // Convert heading (or other text node) to paragraph with same inline content
103
+ return (_schema$nodes$paragra = schema.nodes.paragraph.createAndFill({}, node.content)) !== null && _schema$nodes$paragra !== void 0 ? _schema$nodes$paragra : null;
104
+ };
90
105
  var getBlockNodesInRange = exports.getBlockNodesInRange = function getBlockNodesInRange(range) {
91
106
  if (range.startIndex === range.endIndex) {
92
107
  return [];
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.wrapIntoListStep = void 0;
7
7
  var _nodeChecks = require("./nodeChecks");
8
+ var _utils = require("./utils");
8
9
  var wrapIntoTaskOrDecisionList = function wrapIntoTaskOrDecisionList(nodes, targetNodeTypeName, schema) {
9
10
  var itemNodeType = targetNodeTypeName === 'taskList' ? schema.nodes.taskItem : schema.nodes.decisionItem;
10
11
  var inlineContent = nodes.flatMap(function (node) {
@@ -20,8 +21,15 @@ var wrapIntoTaskOrDecisionList = function wrapIntoTaskOrDecisionList(nodes, targ
20
21
  return outputNode ? [outputNode] : nodes;
21
22
  };
22
23
  var wrapIntoBulletOrOrderedList = function wrapIntoBulletOrOrderedList(nodes, targetNodeTypeName, schema) {
23
- var listItemNode = schema.nodes.listItem.createAndFill({}, nodes);
24
- var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, listItemNode);
24
+ var listItemNodes = nodes.map(function (node) {
25
+ return schema.nodes.listItem.createAndFill({}, node.isTextblock ? (0, _utils.convertTextNodeToParagraph)(node, schema) : node);
26
+ }).filter(function (node) {
27
+ return node !== null;
28
+ });
29
+ if (listItemNodes.length === 0) {
30
+ return nodes;
31
+ }
32
+ var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, listItemNodes);
25
33
  return outputNode ? [outputNode] : nodes;
26
34
  };
27
35
 
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { createBlockMenuRegistry } from './editor-actions';
3
+ import { isTrasformToTargetDisabled } from './editor-actions/isTrasformToTargetDisabled';
3
4
  import { formatNode } from './editor-commands/formatNode';
4
5
  import { transformNode } from './editor-commands/transformNode';
5
6
  import { blockMenuPluginKey, createPlugin } from './pm-plugins/main';
@@ -30,6 +31,20 @@ export const blockMenuPlugin = ({
30
31
  },
31
32
  getBlockMenuComponents: () => {
32
33
  return registry.components;
34
+ },
35
+ isTransformOptionDisabled: (optionNodeTypeName, optionNodeTypeAttrs) => {
36
+ var _api$blockControls, _api$blockControls$sh, _api$selection, _api$selection$shared, _api$selection$shared2;
37
+ const preservedSelection = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.preservedSelection;
38
+ const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
39
+ const currentSelection = preservedSelection || selection;
40
+ if (!currentSelection) {
41
+ return true;
42
+ }
43
+ return isTrasformToTargetDisabled({
44
+ selection: currentSelection,
45
+ targetNodeTypeName: optionNodeTypeName,
46
+ targetNodeTypeAttrs: optionNodeTypeAttrs
47
+ });
33
48
  }
34
49
  },
35
50
  commands: {
@@ -41,7 +56,7 @@ export const blockMenuPlugin = ({
41
56
  }
42
57
  },
43
58
  getSharedState(editorState) {
44
- var _api$blockControls, _api$blockControls$sh, _pluginState$showFlag;
59
+ var _api$blockControls2, _api$blockControls2$s, _pluginState$showFlag;
45
60
  if (!editorState) {
46
61
  return {
47
62
  currentSelectedNodeName: undefined,
@@ -50,7 +65,7 @@ export const blockMenuPlugin = ({
50
65
  }
51
66
 
52
67
  // Get the menuTriggerBy from blockControls plugin if available
53
- const currentSelectedNodeName = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.menuTriggerBy;
68
+ const currentSelectedNodeName = api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$s = _api$blockControls2.sharedState.currentState()) === null || _api$blockControls2$s === void 0 ? void 0 : _api$blockControls2$s.menuTriggerBy;
54
69
 
55
70
  // Get the showFlag from plugin state
56
71
  const pluginState = blockMenuPluginKey.getState(editorState);