@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
|
@@ -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
|
};
|
|
@@ -11,7 +11,6 @@ import { blockMenuPluginKey } from '../pm-plugins/main';
|
|
|
11
11
|
import { useBlockMenu } from './block-menu-provider';
|
|
12
12
|
import { BLOCK_MENU_ITEM_NAME } from './consts';
|
|
13
13
|
import { copyLink } from './utils/copyLink';
|
|
14
|
-
import { isNestedNode } from './utils/isNestedNode';
|
|
15
14
|
const CopyLinkDropdownItemContent = ({
|
|
16
15
|
api,
|
|
17
16
|
config
|
|
@@ -28,14 +27,12 @@ const CopyLinkDropdownItemContent = ({
|
|
|
28
27
|
} = config || {};
|
|
29
28
|
const {
|
|
30
29
|
preservedSelection,
|
|
31
|
-
defaultSelection
|
|
32
|
-
menuTriggerBy
|
|
30
|
+
defaultSelection
|
|
33
31
|
} = useSharedPluginStateWithSelector(api, ['blockControls', 'selection'], ({
|
|
34
32
|
blockControlsState,
|
|
35
33
|
selectionState
|
|
36
34
|
}) => {
|
|
37
35
|
return {
|
|
38
|
-
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
39
36
|
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
40
37
|
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
|
|
41
38
|
};
|
|
@@ -84,8 +81,8 @@ const CopyLinkDropdownItemContent = ({
|
|
|
84
81
|
});
|
|
85
82
|
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, selection]);
|
|
86
83
|
|
|
87
|
-
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
88
|
-
if (!fg('platform_editor_adf_with_localid')
|
|
84
|
+
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
85
|
+
if (!fg('platform_editor_adf_with_localid')) {
|
|
89
86
|
return null;
|
|
90
87
|
}
|
|
91
88
|
return /*#__PURE__*/React.createElement(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 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
|
};
|
package/dist/esm/ui/copy-link.js
CHANGED
|
@@ -11,7 +11,6 @@ import { blockMenuPluginKey } from '../pm-plugins/main';
|
|
|
11
11
|
import { useBlockMenu } from './block-menu-provider';
|
|
12
12
|
import { BLOCK_MENU_ITEM_NAME } from './consts';
|
|
13
13
|
import { copyLink } from './utils/copyLink';
|
|
14
|
-
import { isNestedNode } from './utils/isNestedNode';
|
|
15
14
|
var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
16
15
|
var api = _ref.api,
|
|
17
16
|
config = _ref.config;
|
|
@@ -26,14 +25,12 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
26
25
|
var blockControlsState = _ref3.blockControlsState,
|
|
27
26
|
selectionState = _ref3.selectionState;
|
|
28
27
|
return {
|
|
29
|
-
menuTriggerBy: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.menuTriggerBy,
|
|
30
28
|
preservedSelection: blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.preservedSelection,
|
|
31
29
|
defaultSelection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection
|
|
32
30
|
};
|
|
33
31
|
}),
|
|
34
32
|
preservedSelection = _useSharedPluginState.preservedSelection,
|
|
35
|
-
defaultSelection = _useSharedPluginState.defaultSelection
|
|
36
|
-
menuTriggerBy = _useSharedPluginState.menuTriggerBy;
|
|
33
|
+
defaultSelection = _useSharedPluginState.defaultSelection;
|
|
37
34
|
var selection = preservedSelection || defaultSelection;
|
|
38
35
|
var handleClick = useCallback(function () {
|
|
39
36
|
if (!selection) {
|
|
@@ -76,8 +73,8 @@ var CopyLinkDropdownItemContent = function CopyLinkDropdownItemContent(_ref) {
|
|
|
76
73
|
});
|
|
77
74
|
}, [api, blockLinkHashPrefix, getLinkPath, onDropdownOpenChanged, selection]);
|
|
78
75
|
|
|
79
|
-
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
80
|
-
if (!fg('platform_editor_adf_with_localid')
|
|
76
|
+
// Hide copy link when `platform_editor_adf_with_localid` feature flag is off
|
|
77
|
+
if (!fg('platform_editor_adf_with_localid')) {
|
|
81
78
|
return null;
|
|
82
79
|
}
|
|
83
80
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
@@ -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 {};
|