@atlaskit/editor-plugin-block-menu 5.2.20 → 5.2.22
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 +16 -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/cjs/ui/copy-link.js +3 -6
- 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/es2019/ui/copy-link.js +3 -6
- 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/esm/ui/copy-link.js +3 -6
- 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,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.2.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3356921b0b0ff`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3356921b0b0ff) -
|
|
8
|
+
[ux] Enables 'Copy link to block' feature for nested nodes
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 5.2.21
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`b5d004bf834f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b5d004bf834f8) -
|
|
16
|
+
[ux] Adds block menu action to check if 'Turn into' item should be rendered or not.
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 5.2.20
|
|
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$
|
|
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
|
};
|
package/dist/cjs/ui/copy-link.js
CHANGED
|
@@ -19,7 +19,6 @@ var _main = require("../pm-plugins/main");
|
|
|
19
19
|
var _blockMenuProvider = require("./block-menu-provider");
|
|
20
20
|
var _consts = require("./consts");
|
|
21
21
|
var _copyLink = require("./utils/copyLink");
|
|
22
|
-
var _isNestedNode = require("./utils/isNestedNode");
|
|
23
22
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
24
23
|
var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
25
24
|
var api = _ref.api,
|
|
@@ -35,14 +34,12 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
35
34
|
var blockControlsState = _ref3.blockControlsState,
|
|
36
35
|
selectionState = _ref3.selectionState;
|
|
37
36
|
return {
|
|
38
|
-
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
39
37
|
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
40
38
|
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
|
|
41
39
|
};
|
|
42
40
|
}),
|
|
43
41
|
preservedSelection = _useSharedPluginState.preservedSelection,
|
|
44
|
-
defaultSelection = _useSharedPluginState.defaultSelection
|
|
45
|
-
menuTriggerBy = _useSharedPluginState.menuTriggerBy;
|
|
42
|
+
defaultSelection = _useSharedPluginState.defaultSelection;
|
|
46
43
|
var selection = preservedSelection || defaultSelection;
|
|
47
44
|
var handleClick = (0, _react.useCallback)(function () {
|
|
48
45
|
if (!selection) {
|
|
@@ -85,8 +82,8 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
85
82
|
});
|
|
86
83
|
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, selection]);
|
|
87
84
|
|
|
88
|
-
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
89
|
-
if (!(0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid')
|
|
85
|
+
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
86
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid')) {
|
|
90
87
|
return null;
|
|
91
88
|
}
|
|
92
89
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
@@ -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
|
+
// };
|