@atlaskit/editor-plugin-block-menu 5.2.20 → 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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/blockMenuPlugin.js +17 -2
- package/dist/cjs/editor-actions/isTrasformToTargetDisabled.js +114 -0
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +94 -28
- package/dist/es2019/blockMenuPlugin.js +17 -2
- package/dist/es2019/editor-actions/isTrasformToTargetDisabled.js +110 -0
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +93 -27
- package/dist/esm/blockMenuPlugin.js +17 -2
- package/dist/esm/editor-actions/isTrasformToTargetDisabled.js +108 -0
- package/dist/esm/editor-commands/transform-node-utils/transform.js +93 -27
- package/dist/types/blockMenuPluginType.d.ts +1 -0
- package/dist/types/editor-actions/isTrasformToTargetDisabled.d.ts +11 -0
- package/dist/types/editor-commands/transform-node-utils/transform.d.ts +2 -0
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -0
- package/dist/types-ts4.5/editor-actions/isTrasformToTargetDisabled.d.ts +11 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/transform.d.ts +2 -0
- package/package.json +3 -3
- package/dist/cjs/editor-commands/transform-node-utils/stubStep.js +0 -9
- package/dist/es2019/editor-commands/transform-node-utils/stubStep.js +0 -3
- package/dist/esm/editor-commands/transform-node-utils/stubStep.js +0 -3
- package/dist/types/editor-commands/transform-node-utils/stubStep.d.ts +0 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/stubStep.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 5.2.20
|
|
4
12
|
|
|
5
13
|
### 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$
|
|
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$
|
|
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
|
+
// };
|
|
@@ -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");
|
|
@@ -53,8 +52,10 @@ 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,
|
|
58
59
|
codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
|
|
59
60
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
60
61
|
},
|
|
@@ -63,96 +64,154 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
63
64
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
64
65
|
},
|
|
65
66
|
panel: {
|
|
67
|
+
panel: null,
|
|
66
68
|
layoutSection: [_unwrapStep.unwrapStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
67
69
|
codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
|
|
68
|
-
blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep]
|
|
70
|
+
blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
71
|
+
taskList: null,
|
|
72
|
+
bulletList: null,
|
|
73
|
+
orderedList: null,
|
|
74
|
+
heading: null
|
|
69
75
|
},
|
|
70
76
|
expand: {
|
|
77
|
+
expand: null,
|
|
71
78
|
panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
72
79
|
blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
73
80
|
layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
74
81
|
paragraph: [_unwrapExpandStep.unwrapExpandStep],
|
|
75
|
-
codeBlock:
|
|
82
|
+
codeBlock: null,
|
|
83
|
+
heading: null
|
|
76
84
|
},
|
|
77
85
|
nestedExpand: {
|
|
86
|
+
expand: null,
|
|
87
|
+
nestedExpand: null,
|
|
78
88
|
panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
79
89
|
blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
80
90
|
paragraph: [_unwrapExpandStep.unwrapExpandStep],
|
|
81
|
-
codeBlock:
|
|
91
|
+
codeBlock: null,
|
|
92
|
+
heading: null
|
|
82
93
|
},
|
|
83
94
|
blockquote: {
|
|
95
|
+
blockquote: null,
|
|
84
96
|
expand: [_wrapStep.wrapStep],
|
|
85
97
|
nestedExpand: [_wrapStep.wrapStep],
|
|
86
98
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
87
|
-
codeBlock:
|
|
99
|
+
codeBlock: null,
|
|
88
100
|
decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
|
|
89
101
|
},
|
|
90
102
|
layoutSection: {
|
|
103
|
+
layoutSection: null,
|
|
91
104
|
blockquote: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
92
105
|
expand: [_unwrapLayoutStep.unwrapLayoutStep, _wrapStep.wrapStep],
|
|
93
106
|
panel: [_unwrapLayoutStep.unwrapLayoutStep, _wrapMixedContentStep.wrapMixedContentStep],
|
|
94
|
-
codeBlock:
|
|
95
|
-
paragraph: [_unwrapLayoutStep.unwrapLayoutStep]
|
|
107
|
+
codeBlock: null,
|
|
108
|
+
paragraph: [_unwrapLayoutStep.unwrapLayoutStep],
|
|
109
|
+
heading: null
|
|
96
110
|
},
|
|
97
111
|
codeBlock: {
|
|
112
|
+
codeBlock: null,
|
|
98
113
|
blockquote: [_wrapStep.wrapStep],
|
|
99
114
|
expand: [_wrapStep.wrapStep],
|
|
100
115
|
nestedExpand: [_wrapStep.wrapStep],
|
|
101
116
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
102
|
-
panel: [_wrapStep.wrapStep]
|
|
117
|
+
panel: [_wrapStep.wrapStep],
|
|
118
|
+
heading: null
|
|
103
119
|
},
|
|
104
120
|
bulletList: {
|
|
105
|
-
|
|
106
|
-
codeBlock:
|
|
121
|
+
bulletList: null,
|
|
122
|
+
codeBlock: null,
|
|
107
123
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
108
|
-
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
|
|
124
|
+
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
125
|
+
heading: null
|
|
109
126
|
},
|
|
110
127
|
orderedList: {
|
|
111
|
-
|
|
112
|
-
codeBlock:
|
|
128
|
+
orderedList: null,
|
|
129
|
+
codeBlock: null,
|
|
113
130
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
114
|
-
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
|
|
131
|
+
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
132
|
+
heading: null
|
|
115
133
|
},
|
|
116
134
|
taskList: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
codeBlock: [_stubStep.stubStep],
|
|
135
|
+
blockquote: null,
|
|
136
|
+
codeBlock: null,
|
|
120
137
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
121
|
-
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
|
|
138
|
+
decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep],
|
|
139
|
+
heading: null,
|
|
140
|
+
taskList: null
|
|
122
141
|
},
|
|
123
142
|
table: {
|
|
124
|
-
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
|
|
125
151
|
},
|
|
126
152
|
mediaSingle: {
|
|
127
|
-
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
153
|
+
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
154
|
+
codeBlock: null,
|
|
155
|
+
decisionList: null,
|
|
156
|
+
taskList: null
|
|
128
157
|
},
|
|
129
158
|
mediaGroup: {
|
|
130
|
-
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
159
|
+
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
160
|
+
codeBlock: null
|
|
131
161
|
},
|
|
132
162
|
decisionList: {
|
|
163
|
+
decisionList: null,
|
|
133
164
|
bulletList: [_decisionListToListStep.decisionListToListStep],
|
|
134
165
|
orderedList: [_decisionListToListStep.decisionListToListStep],
|
|
135
166
|
taskList: [_decisionListToListStep.decisionListToListStep],
|
|
136
167
|
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
137
168
|
},
|
|
138
169
|
blockCard: {
|
|
139
|
-
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
|
|
140
177
|
},
|
|
141
178
|
embedCard: {
|
|
142
|
-
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
|
|
143
187
|
},
|
|
144
188
|
extension: {
|
|
145
|
-
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
|
|
189
|
+
layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
|
|
190
|
+
codeBlock: null,
|
|
191
|
+
decisionList: null,
|
|
192
|
+
taskList: null
|
|
146
193
|
},
|
|
147
194
|
bodiedExtension: {
|
|
148
|
-
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
|
|
149
204
|
}
|
|
150
205
|
};
|
|
151
206
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
152
|
-
var _TRANSFORM_STEPS_OVER
|
|
207
|
+
var _TRANSFORM_STEPS_OVER;
|
|
153
208
|
var fromCategory = _types.NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
|
|
154
209
|
var toCategory = _types.NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
|
|
155
|
-
var
|
|
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];
|
|
156
215
|
return steps;
|
|
157
216
|
};
|
|
158
217
|
// Note: Currently works only for single node in the selection
|
|
@@ -183,4 +242,11 @@ var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
|
|
|
183
242
|
return steps.reduce(function (nodes, step) {
|
|
184
243
|
return step(nodes, context);
|
|
185
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;
|
|
186
252
|
};
|
|
@@ -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$
|
|
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$
|
|
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);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { isTransformDisabledBasedOnStepsConfig } from '../editor-commands/transform-node-utils/transform';
|
|
4
|
+
import { toNodeTypeValue } from '../editor-commands/transform-node-utils/types';
|
|
5
|
+
import { getBlockNodesInRange, getTargetNodeTypeNameInContext } from '../editor-commands/transform-node-utils/utils';
|
|
6
|
+
export const canParentContainNodeType = (schema, parentNode, nodeTypeName, nodeTypeAttrs) => {
|
|
7
|
+
const adjustedNodeTypeName = getTargetNodeTypeNameInContext(nodeTypeName, true);
|
|
8
|
+
if (!adjustedNodeTypeName) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const nodeType = schema.nodes[adjustedNodeTypeName];
|
|
12
|
+
return parentNode.type.validContent(Fragment.from(nodeType.createAndFill(nodeTypeAttrs)));
|
|
13
|
+
};
|
|
14
|
+
const isHeadingToHeadingTransformEnabled = (selectedNode, targetNodeTypeAttrs) => {
|
|
15
|
+
var _selectedNode$attrs;
|
|
16
|
+
const selectedLevel = (_selectedNode$attrs = selectedNode.attrs) === null || _selectedNode$attrs === void 0 ? void 0 : _selectedNode$attrs.level;
|
|
17
|
+
const targetLevel = targetNodeTypeAttrs === null || targetNodeTypeAttrs === void 0 ? void 0 : targetNodeTypeAttrs.level;
|
|
18
|
+
if (selectedLevel === undefined || targetLevel === undefined) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return selectedLevel !== targetLevel;
|
|
22
|
+
};
|
|
23
|
+
const isTransformEnabledForNode = (node, targetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema) => {
|
|
24
|
+
const selectedNodeTypeName = toNodeTypeValue(node.type.name);
|
|
25
|
+
if (!selectedNodeTypeName) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const isDisabledByStepsConfig = isTransformDisabledBasedOnStepsConfig(selectedNodeTypeName, targetNodeTypeName);
|
|
29
|
+
if (isDisabledByStepsConfig) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (selectedNodeTypeName === 'heading' && targetNodeTypeName === 'heading') {
|
|
33
|
+
return isHeadingToHeadingTransformEnabled(node, targetNodeTypeAttrs);
|
|
34
|
+
}
|
|
35
|
+
if (isNested && !canParentContainNodeType(schema, parent, targetNodeTypeName, targetNodeTypeAttrs)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
export const isTrasformToTargetDisabled = ({
|
|
41
|
+
selection,
|
|
42
|
+
targetNodeTypeName,
|
|
43
|
+
targetNodeTypeAttrs
|
|
44
|
+
}) => {
|
|
45
|
+
const {
|
|
46
|
+
range
|
|
47
|
+
} = expandSelectionToBlockRange(selection);
|
|
48
|
+
if (!range) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const selectedNodes = getBlockNodesInRange(range);
|
|
52
|
+
const parent = range.parent;
|
|
53
|
+
const isNested = range.depth >= 1;
|
|
54
|
+
const {
|
|
55
|
+
schema
|
|
56
|
+
} = selection.$from.doc.type;
|
|
57
|
+
const supportedTargetNodeTypeName = toNodeTypeValue(targetNodeTypeName);
|
|
58
|
+
if (!supportedTargetNodeTypeName) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const isEnabledForAnyNode = selectedNodes.some(node => isTransformEnabledForNode(node, supportedTargetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema));
|
|
62
|
+
return !isEnabledForAnyNode;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// export const isTrasformToTargetDisabled = ({
|
|
66
|
+
// selection,
|
|
67
|
+
// targetNodeTypeName,
|
|
68
|
+
// targetNodeTypeAttrs,
|
|
69
|
+
// }: TransformDisabledArgs) => {
|
|
70
|
+
// const { range } = expandSelectionToBlockRange(selection);
|
|
71
|
+
// if (!range) {
|
|
72
|
+
// return false;
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
// const selectedNodes = getBlockNodesInRange(range);
|
|
76
|
+
// const parent = range.parent;
|
|
77
|
+
// const isNested = range.depth >= 1;
|
|
78
|
+
|
|
79
|
+
// const { schema } = selection.$from.doc.type;
|
|
80
|
+
|
|
81
|
+
// const isTransformEnabledForAnySelectedNode = selectedNodes.some((node) => {
|
|
82
|
+
// const selectedNodeTypeName = toNodeTypeValue(node.type.name);
|
|
83
|
+
// const supportedTargetNodeTypeName = toNodeTypeValue(targetNodeTypeName);
|
|
84
|
+
// if (!selectedNodeTypeName || !supportedTargetNodeTypeName) {
|
|
85
|
+
// return false;
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// if (isTransformDisabledBasedOnStepsConfig(selectedNodeTypeName, supportedTargetNodeTypeName)) {
|
|
89
|
+
// if (selectedNodeTypeName === 'heading' && supportedTargetNodeTypeName === 'heading') {
|
|
90
|
+
// return isHeadingToHeadingTransformDisabled(node, targetNodeTypeAttrs);
|
|
91
|
+
// }
|
|
92
|
+
// return false;
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
// if (
|
|
96
|
+
// isNested &&
|
|
97
|
+
// !canParentContainNodeType(schema, parent, supportedTargetNodeTypeName, targetNodeTypeAttrs)
|
|
98
|
+
// ) {
|
|
99
|
+
// return false;
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
// return true;
|
|
103
|
+
// });
|
|
104
|
+
|
|
105
|
+
// if (isTransformEnabledForAnySelectedNode) {
|
|
106
|
+
// return false;
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
// return true;
|
|
110
|
+
// };
|
|
@@ -10,7 +10,6 @@ import { unwrapListStep } from './steps/unwrapListStep';
|
|
|
10
10
|
import { wrapBlockquoteToDecisionListStep } from './steps/wrapBlockquoteToDecisionListStep';
|
|
11
11
|
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
12
12
|
import { wrapTextToCodeblockStep } from './steps/wrapTextToCodeblock';
|
|
13
|
-
import { stubStep } from './stubStep';
|
|
14
13
|
import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
15
14
|
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
16
15
|
import { unwrapStep } from './unwrapStep';
|
|
@@ -48,8 +47,10 @@ const TRANSFORM_STEPS = {
|
|
|
48
47
|
|
|
49
48
|
// Transform steps for specific pairs of node types that cannot be processed
|
|
50
49
|
// using generic rules/steps from TRANSFORM_STEPS.
|
|
50
|
+
// Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
|
|
51
51
|
const TRANSFORM_STEPS_OVERRIDE = {
|
|
52
52
|
paragraph: {
|
|
53
|
+
paragraph: null,
|
|
53
54
|
codeBlock: [wrapTextToCodeblockStep],
|
|
54
55
|
layoutSection: [wrapIntoLayoutStep]
|
|
55
56
|
},
|
|
@@ -58,96 +59,154 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
58
59
|
layoutSection: [wrapIntoLayoutStep]
|
|
59
60
|
},
|
|
60
61
|
panel: {
|
|
62
|
+
panel: null,
|
|
61
63
|
layoutSection: [unwrapStep, wrapIntoLayoutStep],
|
|
62
64
|
codeBlock: [unwrapStep, flattenStep, wrapStep],
|
|
63
|
-
blockquote: [unwrapStep, wrapMixedContentStep]
|
|
65
|
+
blockquote: [unwrapStep, wrapMixedContentStep],
|
|
66
|
+
taskList: null,
|
|
67
|
+
bulletList: null,
|
|
68
|
+
orderedList: null,
|
|
69
|
+
heading: null
|
|
64
70
|
},
|
|
65
71
|
expand: {
|
|
72
|
+
expand: null,
|
|
66
73
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
67
74
|
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
68
75
|
layoutSection: [unwrapExpandStep, wrapIntoLayoutStep],
|
|
69
76
|
paragraph: [unwrapExpandStep],
|
|
70
|
-
codeBlock:
|
|
77
|
+
codeBlock: null,
|
|
78
|
+
heading: null
|
|
71
79
|
},
|
|
72
80
|
nestedExpand: {
|
|
81
|
+
expand: null,
|
|
82
|
+
nestedExpand: null,
|
|
73
83
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
74
84
|
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
75
85
|
paragraph: [unwrapExpandStep],
|
|
76
|
-
codeBlock:
|
|
86
|
+
codeBlock: null,
|
|
87
|
+
heading: null
|
|
77
88
|
},
|
|
78
89
|
blockquote: {
|
|
90
|
+
blockquote: null,
|
|
79
91
|
expand: [wrapStep],
|
|
80
92
|
nestedExpand: [wrapStep],
|
|
81
93
|
layoutSection: [wrapIntoLayoutStep],
|
|
82
|
-
codeBlock:
|
|
94
|
+
codeBlock: null,
|
|
83
95
|
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep]
|
|
84
96
|
},
|
|
85
97
|
layoutSection: {
|
|
98
|
+
layoutSection: null,
|
|
86
99
|
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
87
100
|
expand: [unwrapLayoutStep, wrapStep],
|
|
88
101
|
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
89
|
-
codeBlock:
|
|
90
|
-
paragraph: [unwrapLayoutStep]
|
|
102
|
+
codeBlock: null,
|
|
103
|
+
paragraph: [unwrapLayoutStep],
|
|
104
|
+
heading: null
|
|
91
105
|
},
|
|
92
106
|
codeBlock: {
|
|
107
|
+
codeBlock: null,
|
|
93
108
|
blockquote: [wrapStep],
|
|
94
109
|
expand: [wrapStep],
|
|
95
110
|
nestedExpand: [wrapStep],
|
|
96
111
|
layoutSection: [wrapIntoLayoutStep],
|
|
97
|
-
panel: [wrapStep]
|
|
112
|
+
panel: [wrapStep],
|
|
113
|
+
heading: null
|
|
98
114
|
},
|
|
99
115
|
bulletList: {
|
|
100
|
-
|
|
101
|
-
codeBlock:
|
|
116
|
+
bulletList: null,
|
|
117
|
+
codeBlock: null,
|
|
102
118
|
layoutSection: [wrapIntoLayoutStep],
|
|
103
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
119
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
120
|
+
heading: null
|
|
104
121
|
},
|
|
105
122
|
orderedList: {
|
|
106
|
-
|
|
107
|
-
codeBlock:
|
|
123
|
+
orderedList: null,
|
|
124
|
+
codeBlock: null,
|
|
108
125
|
layoutSection: [wrapIntoLayoutStep],
|
|
109
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
126
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
127
|
+
heading: null
|
|
110
128
|
},
|
|
111
129
|
taskList: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
codeBlock: [stubStep],
|
|
130
|
+
blockquote: null,
|
|
131
|
+
codeBlock: null,
|
|
115
132
|
layoutSection: [wrapIntoLayoutStep],
|
|
116
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
133
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
134
|
+
heading: null,
|
|
135
|
+
taskList: null
|
|
117
136
|
},
|
|
118
137
|
table: {
|
|
119
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
138
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
139
|
+
blockquote: null,
|
|
140
|
+
panel: null,
|
|
141
|
+
codeBlock: null,
|
|
142
|
+
orderedList: null,
|
|
143
|
+
bulletList: null,
|
|
144
|
+
taskList: null,
|
|
145
|
+
decisionList: null
|
|
120
146
|
},
|
|
121
147
|
mediaSingle: {
|
|
122
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
148
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
149
|
+
codeBlock: null,
|
|
150
|
+
decisionList: null,
|
|
151
|
+
taskList: null
|
|
123
152
|
},
|
|
124
153
|
mediaGroup: {
|
|
125
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
154
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
155
|
+
codeBlock: null
|
|
126
156
|
},
|
|
127
157
|
decisionList: {
|
|
158
|
+
decisionList: null,
|
|
128
159
|
bulletList: [decisionListToListStep],
|
|
129
160
|
orderedList: [decisionListToListStep],
|
|
130
161
|
taskList: [decisionListToListStep],
|
|
131
162
|
layoutSection: [wrapIntoLayoutStep]
|
|
132
163
|
},
|
|
133
164
|
blockCard: {
|
|
134
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
165
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
166
|
+
blockquote: null,
|
|
167
|
+
codeBlock: null,
|
|
168
|
+
orderedList: null,
|
|
169
|
+
bulletList: null,
|
|
170
|
+
taskList: null,
|
|
171
|
+
decisionList: null
|
|
135
172
|
},
|
|
136
173
|
embedCard: {
|
|
137
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
174
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
175
|
+
blockquote: null,
|
|
176
|
+
panel: null,
|
|
177
|
+
codeBlock: null,
|
|
178
|
+
orderedList: null,
|
|
179
|
+
bulletList: null,
|
|
180
|
+
taskList: null,
|
|
181
|
+
decisionList: null
|
|
138
182
|
},
|
|
139
183
|
extension: {
|
|
140
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
184
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
185
|
+
codeBlock: null,
|
|
186
|
+
decisionList: null,
|
|
187
|
+
taskList: null
|
|
141
188
|
},
|
|
142
189
|
bodiedExtension: {
|
|
143
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
190
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
191
|
+
blockquote: null,
|
|
192
|
+
expand: null,
|
|
193
|
+
panel: null,
|
|
194
|
+
codeBlock: null,
|
|
195
|
+
orderedList: null,
|
|
196
|
+
bulletList: null,
|
|
197
|
+
taskList: null,
|
|
198
|
+
decisionList: null
|
|
144
199
|
}
|
|
145
200
|
};
|
|
146
201
|
const getTransformStepsForNodeTypes = (selectedNodeTypeName, targetNodeTypeName) => {
|
|
147
|
-
var _TRANSFORM_STEPS_OVER
|
|
202
|
+
var _TRANSFORM_STEPS_OVER;
|
|
148
203
|
const fromCategory = NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
|
|
149
204
|
const toCategory = NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
|
|
150
|
-
const
|
|
205
|
+
const overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
|
|
206
|
+
if (overrideSteps === null) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
|
|
151
210
|
return steps;
|
|
152
211
|
};
|
|
153
212
|
// Note: Currently works only for single node in the selection
|
|
@@ -179,4 +238,11 @@ export const getOutputNodes = ({
|
|
|
179
238
|
return steps.reduce((nodes, step) => {
|
|
180
239
|
return step(nodes, context);
|
|
181
240
|
}, nodesToReplace);
|
|
241
|
+
};
|
|
242
|
+
export const isTransformDisabledBasedOnStepsConfig = (selectedNodeType, targetNodeType) => {
|
|
243
|
+
const steps = getTransformStepsForNodeTypes(selectedNodeType, targetNodeType);
|
|
244
|
+
if (!steps || steps.length === 0) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
182
248
|
};
|
|
@@ -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 as _formatNode } from './editor-commands/formatNode';
|
|
4
5
|
import { transformNode as _transformNode } from './editor-commands/transformNode';
|
|
5
6
|
import { blockMenuPluginKey, createPlugin } from './pm-plugins/main';
|
|
@@ -29,6 +30,20 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
29
30
|
},
|
|
30
31
|
getBlockMenuComponents: function getBlockMenuComponents() {
|
|
31
32
|
return registry.components;
|
|
33
|
+
},
|
|
34
|
+
isTransformOptionDisabled: function isTransformOptionDisabled(optionNodeTypeName, optionNodeTypeAttrs) {
|
|
35
|
+
var _api$blockControls, _api$selection;
|
|
36
|
+
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;
|
|
37
|
+
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;
|
|
38
|
+
var currentSelection = preservedSelection || selection;
|
|
39
|
+
if (!currentSelection) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return isTrasformToTargetDisabled({
|
|
43
|
+
selection: currentSelection,
|
|
44
|
+
targetNodeTypeName: optionNodeTypeName,
|
|
45
|
+
targetNodeTypeAttrs: optionNodeTypeAttrs
|
|
46
|
+
});
|
|
32
47
|
}
|
|
33
48
|
},
|
|
34
49
|
commands: {
|
|
@@ -40,7 +55,7 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
40
55
|
}
|
|
41
56
|
},
|
|
42
57
|
getSharedState: function getSharedState(editorState) {
|
|
43
|
-
var _api$
|
|
58
|
+
var _api$blockControls2, _pluginState$showFlag;
|
|
44
59
|
if (!editorState) {
|
|
45
60
|
return {
|
|
46
61
|
currentSelectedNodeName: undefined,
|
|
@@ -49,7 +64,7 @@ export var blockMenuPlugin = function blockMenuPlugin(_ref) {
|
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
// Get the menuTriggerBy from blockControls plugin if available
|
|
52
|
-
var currentSelectedNodeName = api === null || api === void 0 || (_api$
|
|
67
|
+
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;
|
|
53
68
|
|
|
54
69
|
// Get the showFlag from plugin state
|
|
55
70
|
var pluginState = blockMenuPluginKey.getState(editorState);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { isTransformDisabledBasedOnStepsConfig } from '../editor-commands/transform-node-utils/transform';
|
|
4
|
+
import { toNodeTypeValue } from '../editor-commands/transform-node-utils/types';
|
|
5
|
+
import { getBlockNodesInRange, getTargetNodeTypeNameInContext } from '../editor-commands/transform-node-utils/utils';
|
|
6
|
+
export var canParentContainNodeType = function canParentContainNodeType(schema, parentNode, nodeTypeName, nodeTypeAttrs) {
|
|
7
|
+
var adjustedNodeTypeName = getTargetNodeTypeNameInContext(nodeTypeName, true);
|
|
8
|
+
if (!adjustedNodeTypeName) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
var nodeType = schema.nodes[adjustedNodeTypeName];
|
|
12
|
+
return parentNode.type.validContent(Fragment.from(nodeType.createAndFill(nodeTypeAttrs)));
|
|
13
|
+
};
|
|
14
|
+
var isHeadingToHeadingTransformEnabled = function isHeadingToHeadingTransformEnabled(selectedNode, targetNodeTypeAttrs) {
|
|
15
|
+
var _selectedNode$attrs;
|
|
16
|
+
var selectedLevel = (_selectedNode$attrs = selectedNode.attrs) === null || _selectedNode$attrs === void 0 ? void 0 : _selectedNode$attrs.level;
|
|
17
|
+
var targetLevel = targetNodeTypeAttrs === null || targetNodeTypeAttrs === void 0 ? void 0 : targetNodeTypeAttrs.level;
|
|
18
|
+
if (selectedLevel === undefined || targetLevel === undefined) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return selectedLevel !== targetLevel;
|
|
22
|
+
};
|
|
23
|
+
var isTransformEnabledForNode = function isTransformEnabledForNode(node, targetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema) {
|
|
24
|
+
var selectedNodeTypeName = toNodeTypeValue(node.type.name);
|
|
25
|
+
if (!selectedNodeTypeName) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
var isDisabledByStepsConfig = isTransformDisabledBasedOnStepsConfig(selectedNodeTypeName, targetNodeTypeName);
|
|
29
|
+
if (isDisabledByStepsConfig) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (selectedNodeTypeName === 'heading' && targetNodeTypeName === 'heading') {
|
|
33
|
+
return isHeadingToHeadingTransformEnabled(node, targetNodeTypeAttrs);
|
|
34
|
+
}
|
|
35
|
+
if (isNested && !canParentContainNodeType(schema, parent, targetNodeTypeName, targetNodeTypeAttrs)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
export var isTrasformToTargetDisabled = function isTrasformToTargetDisabled(_ref) {
|
|
41
|
+
var selection = _ref.selection,
|
|
42
|
+
targetNodeTypeName = _ref.targetNodeTypeName,
|
|
43
|
+
targetNodeTypeAttrs = _ref.targetNodeTypeAttrs;
|
|
44
|
+
var _expandSelectionToBlo = expandSelectionToBlockRange(selection),
|
|
45
|
+
range = _expandSelectionToBlo.range;
|
|
46
|
+
if (!range) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
var selectedNodes = getBlockNodesInRange(range);
|
|
50
|
+
var parent = range.parent;
|
|
51
|
+
var isNested = range.depth >= 1;
|
|
52
|
+
var schema = selection.$from.doc.type.schema;
|
|
53
|
+
var supportedTargetNodeTypeName = toNodeTypeValue(targetNodeTypeName);
|
|
54
|
+
if (!supportedTargetNodeTypeName) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
var isEnabledForAnyNode = selectedNodes.some(function (node) {
|
|
58
|
+
return isTransformEnabledForNode(node, supportedTargetNodeTypeName, targetNodeTypeAttrs, isNested, parent, schema);
|
|
59
|
+
});
|
|
60
|
+
return !isEnabledForAnyNode;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// export const isTrasformToTargetDisabled = ({
|
|
64
|
+
// selection,
|
|
65
|
+
// targetNodeTypeName,
|
|
66
|
+
// targetNodeTypeAttrs,
|
|
67
|
+
// }: TransformDisabledArgs) => {
|
|
68
|
+
// const { range } = expandSelectionToBlockRange(selection);
|
|
69
|
+
// if (!range) {
|
|
70
|
+
// return false;
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// const selectedNodes = getBlockNodesInRange(range);
|
|
74
|
+
// const parent = range.parent;
|
|
75
|
+
// const isNested = range.depth >= 1;
|
|
76
|
+
|
|
77
|
+
// const { schema } = selection.$from.doc.type;
|
|
78
|
+
|
|
79
|
+
// const isTransformEnabledForAnySelectedNode = selectedNodes.some((node) => {
|
|
80
|
+
// const selectedNodeTypeName = toNodeTypeValue(node.type.name);
|
|
81
|
+
// const supportedTargetNodeTypeName = toNodeTypeValue(targetNodeTypeName);
|
|
82
|
+
// if (!selectedNodeTypeName || !supportedTargetNodeTypeName) {
|
|
83
|
+
// return false;
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
// if (isTransformDisabledBasedOnStepsConfig(selectedNodeTypeName, supportedTargetNodeTypeName)) {
|
|
87
|
+
// if (selectedNodeTypeName === 'heading' && supportedTargetNodeTypeName === 'heading') {
|
|
88
|
+
// return isHeadingToHeadingTransformDisabled(node, targetNodeTypeAttrs);
|
|
89
|
+
// }
|
|
90
|
+
// return false;
|
|
91
|
+
// }
|
|
92
|
+
|
|
93
|
+
// if (
|
|
94
|
+
// isNested &&
|
|
95
|
+
// !canParentContainNodeType(schema, parent, supportedTargetNodeTypeName, targetNodeTypeAttrs)
|
|
96
|
+
// ) {
|
|
97
|
+
// return false;
|
|
98
|
+
// }
|
|
99
|
+
|
|
100
|
+
// return true;
|
|
101
|
+
// });
|
|
102
|
+
|
|
103
|
+
// if (isTransformEnabledForAnySelectedNode) {
|
|
104
|
+
// return false;
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// return true;
|
|
108
|
+
// };
|
|
@@ -10,7 +10,6 @@ import { unwrapListStep } from './steps/unwrapListStep';
|
|
|
10
10
|
import { wrapBlockquoteToDecisionListStep } from './steps/wrapBlockquoteToDecisionListStep';
|
|
11
11
|
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
12
12
|
import { wrapTextToCodeblockStep } from './steps/wrapTextToCodeblock';
|
|
13
|
-
import { stubStep } from './stubStep';
|
|
14
13
|
import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
15
14
|
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
16
15
|
import { unwrapStep } from './unwrapStep';
|
|
@@ -48,8 +47,10 @@ var TRANSFORM_STEPS = {
|
|
|
48
47
|
|
|
49
48
|
// Transform steps for specific pairs of node types that cannot be processed
|
|
50
49
|
// using generic rules/steps from TRANSFORM_STEPS.
|
|
50
|
+
// Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
|
|
51
51
|
var TRANSFORM_STEPS_OVERRIDE = {
|
|
52
52
|
paragraph: {
|
|
53
|
+
paragraph: null,
|
|
53
54
|
codeBlock: [wrapTextToCodeblockStep],
|
|
54
55
|
layoutSection: [wrapIntoLayoutStep]
|
|
55
56
|
},
|
|
@@ -58,96 +59,154 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
58
59
|
layoutSection: [wrapIntoLayoutStep]
|
|
59
60
|
},
|
|
60
61
|
panel: {
|
|
62
|
+
panel: null,
|
|
61
63
|
layoutSection: [unwrapStep, wrapIntoLayoutStep],
|
|
62
64
|
codeBlock: [unwrapStep, flattenStep, wrapStep],
|
|
63
|
-
blockquote: [unwrapStep, wrapMixedContentStep]
|
|
65
|
+
blockquote: [unwrapStep, wrapMixedContentStep],
|
|
66
|
+
taskList: null,
|
|
67
|
+
bulletList: null,
|
|
68
|
+
orderedList: null,
|
|
69
|
+
heading: null
|
|
64
70
|
},
|
|
65
71
|
expand: {
|
|
72
|
+
expand: null,
|
|
66
73
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
67
74
|
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
68
75
|
layoutSection: [unwrapExpandStep, wrapIntoLayoutStep],
|
|
69
76
|
paragraph: [unwrapExpandStep],
|
|
70
|
-
codeBlock:
|
|
77
|
+
codeBlock: null,
|
|
78
|
+
heading: null
|
|
71
79
|
},
|
|
72
80
|
nestedExpand: {
|
|
81
|
+
expand: null,
|
|
82
|
+
nestedExpand: null,
|
|
73
83
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
74
84
|
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
75
85
|
paragraph: [unwrapExpandStep],
|
|
76
|
-
codeBlock:
|
|
86
|
+
codeBlock: null,
|
|
87
|
+
heading: null
|
|
77
88
|
},
|
|
78
89
|
blockquote: {
|
|
90
|
+
blockquote: null,
|
|
79
91
|
expand: [wrapStep],
|
|
80
92
|
nestedExpand: [wrapStep],
|
|
81
93
|
layoutSection: [wrapIntoLayoutStep],
|
|
82
|
-
codeBlock:
|
|
94
|
+
codeBlock: null,
|
|
83
95
|
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep]
|
|
84
96
|
},
|
|
85
97
|
layoutSection: {
|
|
98
|
+
layoutSection: null,
|
|
86
99
|
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
87
100
|
expand: [unwrapLayoutStep, wrapStep],
|
|
88
101
|
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
89
|
-
codeBlock:
|
|
90
|
-
paragraph: [unwrapLayoutStep]
|
|
102
|
+
codeBlock: null,
|
|
103
|
+
paragraph: [unwrapLayoutStep],
|
|
104
|
+
heading: null
|
|
91
105
|
},
|
|
92
106
|
codeBlock: {
|
|
107
|
+
codeBlock: null,
|
|
93
108
|
blockquote: [wrapStep],
|
|
94
109
|
expand: [wrapStep],
|
|
95
110
|
nestedExpand: [wrapStep],
|
|
96
111
|
layoutSection: [wrapIntoLayoutStep],
|
|
97
|
-
panel: [wrapStep]
|
|
112
|
+
panel: [wrapStep],
|
|
113
|
+
heading: null
|
|
98
114
|
},
|
|
99
115
|
bulletList: {
|
|
100
|
-
|
|
101
|
-
codeBlock:
|
|
116
|
+
bulletList: null,
|
|
117
|
+
codeBlock: null,
|
|
102
118
|
layoutSection: [wrapIntoLayoutStep],
|
|
103
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
119
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
120
|
+
heading: null
|
|
104
121
|
},
|
|
105
122
|
orderedList: {
|
|
106
|
-
|
|
107
|
-
codeBlock:
|
|
123
|
+
orderedList: null,
|
|
124
|
+
codeBlock: null,
|
|
108
125
|
layoutSection: [wrapIntoLayoutStep],
|
|
109
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
126
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
127
|
+
heading: null
|
|
110
128
|
},
|
|
111
129
|
taskList: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
codeBlock: [stubStep],
|
|
130
|
+
blockquote: null,
|
|
131
|
+
codeBlock: null,
|
|
115
132
|
layoutSection: [wrapIntoLayoutStep],
|
|
116
|
-
decisionList: [flattenListStep, listToDecisionListStep]
|
|
133
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
134
|
+
heading: null,
|
|
135
|
+
taskList: null
|
|
117
136
|
},
|
|
118
137
|
table: {
|
|
119
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
138
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
139
|
+
blockquote: null,
|
|
140
|
+
panel: null,
|
|
141
|
+
codeBlock: null,
|
|
142
|
+
orderedList: null,
|
|
143
|
+
bulletList: null,
|
|
144
|
+
taskList: null,
|
|
145
|
+
decisionList: null
|
|
120
146
|
},
|
|
121
147
|
mediaSingle: {
|
|
122
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
148
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
149
|
+
codeBlock: null,
|
|
150
|
+
decisionList: null,
|
|
151
|
+
taskList: null
|
|
123
152
|
},
|
|
124
153
|
mediaGroup: {
|
|
125
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
154
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
155
|
+
codeBlock: null
|
|
126
156
|
},
|
|
127
157
|
decisionList: {
|
|
158
|
+
decisionList: null,
|
|
128
159
|
bulletList: [decisionListToListStep],
|
|
129
160
|
orderedList: [decisionListToListStep],
|
|
130
161
|
taskList: [decisionListToListStep],
|
|
131
162
|
layoutSection: [wrapIntoLayoutStep]
|
|
132
163
|
},
|
|
133
164
|
blockCard: {
|
|
134
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
165
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
166
|
+
blockquote: null,
|
|
167
|
+
codeBlock: null,
|
|
168
|
+
orderedList: null,
|
|
169
|
+
bulletList: null,
|
|
170
|
+
taskList: null,
|
|
171
|
+
decisionList: null
|
|
135
172
|
},
|
|
136
173
|
embedCard: {
|
|
137
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
174
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
175
|
+
blockquote: null,
|
|
176
|
+
panel: null,
|
|
177
|
+
codeBlock: null,
|
|
178
|
+
orderedList: null,
|
|
179
|
+
bulletList: null,
|
|
180
|
+
taskList: null,
|
|
181
|
+
decisionList: null
|
|
138
182
|
},
|
|
139
183
|
extension: {
|
|
140
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
184
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
185
|
+
codeBlock: null,
|
|
186
|
+
decisionList: null,
|
|
187
|
+
taskList: null
|
|
141
188
|
},
|
|
142
189
|
bodiedExtension: {
|
|
143
|
-
layoutSection: [wrapIntoLayoutStep]
|
|
190
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
191
|
+
blockquote: null,
|
|
192
|
+
expand: null,
|
|
193
|
+
panel: null,
|
|
194
|
+
codeBlock: null,
|
|
195
|
+
orderedList: null,
|
|
196
|
+
bulletList: null,
|
|
197
|
+
taskList: null,
|
|
198
|
+
decisionList: null
|
|
144
199
|
}
|
|
145
200
|
};
|
|
146
201
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
147
|
-
var _TRANSFORM_STEPS_OVER
|
|
202
|
+
var _TRANSFORM_STEPS_OVER;
|
|
148
203
|
var fromCategory = NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
|
|
149
204
|
var toCategory = NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
|
|
150
|
-
var
|
|
205
|
+
var overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
|
|
206
|
+
if (overrideSteps === null) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
var steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
|
|
151
210
|
return steps;
|
|
152
211
|
};
|
|
153
212
|
// Note: Currently works only for single node in the selection
|
|
@@ -178,4 +237,11 @@ export var getOutputNodes = function getOutputNodes(_ref) {
|
|
|
178
237
|
return steps.reduce(function (nodes, step) {
|
|
179
238
|
return step(nodes, context);
|
|
180
239
|
}, nodesToReplace);
|
|
240
|
+
};
|
|
241
|
+
export var isTransformDisabledBasedOnStepsConfig = function isTransformDisabledBasedOnStepsConfig(selectedNodeType, targetNodeType) {
|
|
242
|
+
var steps = getTransformStepsForNodeTypes(selectedNodeType, targetNodeType);
|
|
243
|
+
if (!steps || steps.length === 0) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
181
247
|
};
|
|
@@ -14,6 +14,7 @@ type TransformNodeCommand = (targetType: NodeType, metadata?: TransformNodeMetad
|
|
|
14
14
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
15
15
|
actions: {
|
|
16
16
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
17
|
+
isTransformOptionDisabled: (optionNodeTypeName: string, optionNodeTypeAttrs?: Record<string, unknown>) => boolean;
|
|
17
18
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
18
19
|
};
|
|
19
20
|
commands: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { type NodeTypeName } from '../editor-commands/transform-node-utils/types';
|
|
4
|
+
type TransformDisabledArgs = {
|
|
5
|
+
selection: Selection;
|
|
6
|
+
targetNodeTypeAttrs?: Record<string, unknown>;
|
|
7
|
+
targetNodeTypeName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const canParentContainNodeType: (schema: Schema, parentNode: PMNode, nodeTypeName: NodeTypeName, nodeTypeAttrs?: Record<string, unknown>) => boolean;
|
|
10
|
+
export declare const isTrasformToTargetDisabled: ({ selection, targetNodeTypeName, targetNodeTypeAttrs, }: TransformDisabledArgs) => boolean;
|
|
11
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Node as PMNode, type NodeType, type Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { NodeTypeName } from './types';
|
|
2
3
|
interface GetOutputNodesArgs {
|
|
3
4
|
isNested: boolean;
|
|
4
5
|
schema: Schema;
|
|
@@ -7,4 +8,5 @@ interface GetOutputNodesArgs {
|
|
|
7
8
|
targetNodeType: NodeType;
|
|
8
9
|
}
|
|
9
10
|
export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, isNested, targetAttrs, }: GetOutputNodesArgs) => PMNode[] | undefined;
|
|
11
|
+
export declare const isTransformDisabledBasedOnStepsConfig: (selectedNodeType: NodeTypeName, targetNodeType: NodeTypeName) => boolean;
|
|
10
12
|
export {};
|
|
@@ -14,6 +14,7 @@ type TransformNodeCommand = (targetType: NodeType, metadata?: TransformNodeMetad
|
|
|
14
14
|
export type BlockMenuPlugin = NextEditorPlugin<'blockMenu', {
|
|
15
15
|
actions: {
|
|
16
16
|
getBlockMenuComponents: () => Array<RegisterBlockMenuComponent>;
|
|
17
|
+
isTransformOptionDisabled: (optionNodeTypeName: string, optionNodeTypeAttrs?: Record<string, unknown>) => boolean;
|
|
17
18
|
registerBlockMenuComponents: (blockMenuComponents: Array<RegisterBlockMenuComponent>) => void;
|
|
18
19
|
};
|
|
19
20
|
commands: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { type NodeTypeName } from '../editor-commands/transform-node-utils/types';
|
|
4
|
+
type TransformDisabledArgs = {
|
|
5
|
+
selection: Selection;
|
|
6
|
+
targetNodeTypeAttrs?: Record<string, unknown>;
|
|
7
|
+
targetNodeTypeName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const canParentContainNodeType: (schema: Schema, parentNode: PMNode, nodeTypeName: NodeTypeName, nodeTypeAttrs?: Record<string, unknown>) => boolean;
|
|
10
|
+
export declare const isTrasformToTargetDisabled: ({ selection, targetNodeTypeName, targetNodeTypeAttrs, }: TransformDisabledArgs) => boolean;
|
|
11
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Node as PMNode, type NodeType, type Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { NodeTypeName } from './types';
|
|
2
3
|
interface GetOutputNodesArgs {
|
|
3
4
|
isNested: boolean;
|
|
4
5
|
schema: Schema;
|
|
@@ -7,4 +8,5 @@ interface GetOutputNodesArgs {
|
|
|
7
8
|
targetNodeType: NodeType;
|
|
8
9
|
}
|
|
9
10
|
export declare const getOutputNodes: ({ sourceNode, targetNodeType, schema, isNested, targetAttrs, }: GetOutputNodesArgs) => PMNode[] | undefined;
|
|
11
|
+
export declare const isTransformDisabledBasedOnStepsConfig: (selectedNodeType: NodeTypeName, targetNodeType: NodeTypeName) => boolean;
|
|
10
12
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.21",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,12 +44,12 @@
|
|
|
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.1.0",
|
|
48
48
|
"@atlaskit/tokens": "^9.0.0",
|
|
49
49
|
"@babel/runtime": "^7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@atlaskit/editor-common": "^110.
|
|
52
|
+
"@atlaskit/editor-common": "^110.48.0",
|
|
53
53
|
"react": "^18.2.0",
|
|
54
54
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
55
55
|
},
|