@atlaskit/editor-plugin-block-menu 6.0.9 → 6.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +224 -0
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +4 -238
- package/dist/cjs/ui/block-menu-components.js +12 -0
- package/dist/cjs/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/cjs/ui/block-menu-renderer/utils.js +4 -7
- package/dist/cjs/ui/hooks/useSuggestedItems.js +4 -37
- package/dist/cjs/ui/utils/createMenuItemsMap.js +19 -0
- package/dist/cjs/ui/utils/getSuggestedItemsFromSelection.js +40 -0
- package/dist/es2019/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +56 -1
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +5 -240
- package/dist/es2019/ui/block-menu-components.js +13 -1
- package/dist/es2019/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/es2019/ui/block-menu-renderer/utils.js +4 -7
- package/dist/es2019/ui/hooks/useSuggestedItems.js +4 -28
- package/dist/es2019/ui/utils/createMenuItemsMap.js +9 -0
- package/dist/es2019/ui/utils/getSuggestedItemsFromSelection.js +30 -0
- package/dist/esm/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.js +219 -0
- package/dist/esm/editor-commands/transform-node-utils/steps/convertEachNodeStep.js +58 -1
- package/dist/esm/editor-commands/transform-node-utils/transform.js +5 -240
- package/dist/esm/ui/block-menu-components.js +12 -0
- package/dist/esm/ui/block-menu-renderer/BlockMenuComponent.js +3 -3
- package/dist/esm/ui/block-menu-renderer/utils.js +4 -7
- package/dist/esm/ui/hooks/useSuggestedItems.js +4 -37
- package/dist/esm/ui/utils/createMenuItemsMap.js +13 -0
- package/dist/esm/ui/utils/getSuggestedItemsFromSelection.js +35 -0
- package/dist/types/blockMenuPluginType.d.ts +1 -0
- package/dist/types/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
- package/dist/types/ui/block-menu-renderer/utils.d.ts +2 -3
- package/dist/types/ui/utils/createMenuItemsMap.d.ts +6 -0
- package/dist/types/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
- package/dist/types-ts4.5/blockMenuPluginType.d.ts +1 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/TRANSFORMATION_MATRIX.d.ts +2 -0
- package/dist/types-ts4.5/ui/block-menu-renderer/utils.d.ts +2 -3
- package/dist/types-ts4.5/ui/utils/createMenuItemsMap.d.ts +6 -0
- package/dist/types-ts4.5/ui/utils/getSuggestedItemsFromSelection.d.ts +6 -0
- package/package.json +6 -6
|
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useSuggestedItems = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var _suggestedItemsRank = require("../utils/suggested-items-rank");
|
|
9
|
+
var _createMenuItemsMap = require("../utils/createMenuItemsMap");
|
|
10
|
+
var _getSuggestedItemsFromSelection = require("../utils/getSuggestedItemsFromSelection");
|
|
12
11
|
var useSuggestedItems = exports.useSuggestedItems = function useSuggestedItems(api) {
|
|
13
12
|
var _api$blockMenu;
|
|
14
13
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls', 'selection'], function (states) {
|
|
@@ -22,43 +21,11 @@ var useSuggestedItems = exports.useSuggestedItems = function useSuggestedItems(a
|
|
|
22
21
|
selection = _useSharedPluginState.selection;
|
|
23
22
|
var blockMenuComponents = api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 ? void 0 : _api$blockMenu.actions.getBlockMenuComponents();
|
|
24
23
|
var menuItemsMap = (0, _react.useMemo)(function () {
|
|
25
|
-
|
|
26
|
-
return new Map();
|
|
27
|
-
}
|
|
28
|
-
return new Map(blockMenuComponents.filter(function (c) {
|
|
29
|
-
return c.type === 'block-menu-item';
|
|
30
|
-
}).map(function (item) {
|
|
31
|
-
return [item.key, item];
|
|
32
|
-
}));
|
|
24
|
+
return (0, _createMenuItemsMap.createMenuItemsMap)(blockMenuComponents);
|
|
33
25
|
}, [blockMenuComponents]);
|
|
34
26
|
var suggestedItems = (0, _react.useMemo)(function () {
|
|
35
27
|
var currentSelection = preservedSelection || selection;
|
|
36
|
-
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
var _expandSelectionToBlo = (0, _selection.expandSelectionToBlockRange)(currentSelection),
|
|
40
|
-
range = _expandSelectionToBlo.range;
|
|
41
|
-
if (!range) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
var blockNodes = (0, _utils.getBlockNodesInRange)(range);
|
|
45
|
-
if (blockNodes.length === 0) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
var firstNodeType = blockNodes[0].type.name;
|
|
49
|
-
var allSameType = blockNodes.every(function (node) {
|
|
50
|
-
return node.type.name === firstNodeType;
|
|
51
|
-
});
|
|
52
|
-
if (!allSameType) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
var nodeTypeName = firstNodeType;
|
|
56
|
-
var sortedKeys = (0, _suggestedItemsRank.getSortedSuggestedItems)(nodeTypeName);
|
|
57
|
-
return sortedKeys.map(function (key) {
|
|
58
|
-
return menuItemsMap.get(key);
|
|
59
|
-
}).filter(function (item) {
|
|
60
|
-
return item !== undefined;
|
|
61
|
-
});
|
|
28
|
+
return (0, _getSuggestedItemsFromSelection.getSuggestedItemsFromSelection)(menuItemsMap, currentSelection);
|
|
62
29
|
}, [menuItemsMap, preservedSelection, selection]);
|
|
63
30
|
return suggestedItems;
|
|
64
31
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createMenuItemsMap = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to create menu items map from block menu components.
|
|
9
|
+
*/
|
|
10
|
+
var createMenuItemsMap = exports.createMenuItemsMap = function createMenuItemsMap(blockMenuComponents) {
|
|
11
|
+
if (!blockMenuComponents) {
|
|
12
|
+
return new Map();
|
|
13
|
+
}
|
|
14
|
+
return new Map(blockMenuComponents.filter(function (c) {
|
|
15
|
+
return c.type === 'block-menu-item';
|
|
16
|
+
}).map(function (item) {
|
|
17
|
+
return [item.key, item];
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSuggestedItemsFromSelection = void 0;
|
|
7
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
|
+
var _utils = require("../../editor-commands/transform-node-utils/utils");
|
|
9
|
+
var _suggestedItemsRank = require("../utils/suggested-items-rank");
|
|
10
|
+
/**
|
|
11
|
+
* Pure function to calculate suggested items based on selection and menu components.
|
|
12
|
+
*/
|
|
13
|
+
var getSuggestedItemsFromSelection = exports.getSuggestedItemsFromSelection = function getSuggestedItemsFromSelection(menuItemsMap, currentSelection) {
|
|
14
|
+
if (menuItemsMap.size === 0 || !currentSelection) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
var _expandSelectionToBlo = (0, _selection.expandSelectionToBlockRange)(currentSelection),
|
|
18
|
+
range = _expandSelectionToBlo.range;
|
|
19
|
+
if (!range) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
var blockNodes = (0, _utils.getBlockNodesInRange)(range);
|
|
23
|
+
if (blockNodes.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
var firstNodeType = blockNodes[0].type.name;
|
|
27
|
+
var allSameType = blockNodes.every(function (node) {
|
|
28
|
+
return node.type.name === firstNodeType;
|
|
29
|
+
});
|
|
30
|
+
if (!allSameType) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
var nodeTypeName = firstNodeType;
|
|
34
|
+
var sortedKeys = (0, _suggestedItemsRank.getSortedSuggestedItems)(nodeTypeName);
|
|
35
|
+
return sortedKeys.map(function (key) {
|
|
36
|
+
return menuItemsMap.get(key);
|
|
37
|
+
}).filter(function (item) {
|
|
38
|
+
return item !== undefined;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { flattenStep } from './flattenStep';
|
|
2
|
+
import { applyTargetTextTypeStep } from './steps/applyTargetTextTypeStep';
|
|
3
|
+
import { convertEachNodeStep } from './steps/convertEachNodeStep';
|
|
4
|
+
import { decisionListToListStep } from './steps/decisionListToListStep';
|
|
5
|
+
import { flattenListStep } from './steps/flattenListStep';
|
|
6
|
+
import { listToDecisionListStep } from './steps/listToDecisionListStep';
|
|
7
|
+
import { listToListStep } from './steps/listToListStep';
|
|
8
|
+
import { mergeNeighbourListsStep } from './steps/mergeNeighbourListsStep';
|
|
9
|
+
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
10
|
+
import { unwrapListStep } from './steps/unwrapListStep';
|
|
11
|
+
import { wrapBlockquoteToDecisionListStep } from './steps/wrapBlockquoteToDecisionListStep';
|
|
12
|
+
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
13
|
+
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
14
|
+
import { unwrapStep } from './unwrapStep';
|
|
15
|
+
import { wrapIntoListStep } from './wrapIntoListStep';
|
|
16
|
+
import { wrapStep } from './wrapStep';
|
|
17
|
+
|
|
18
|
+
// Transform steps for all node type pairs.
|
|
19
|
+
// If a transformation is not defined (undefined), it is not available.
|
|
20
|
+
export const TRANSFORMATION_MATRIX = {
|
|
21
|
+
paragraph: {
|
|
22
|
+
heading: [flattenStep, applyTargetTextTypeStep],
|
|
23
|
+
blockquote: [wrapMixedContentStep],
|
|
24
|
+
codeBlock: [wrapMixedContentStep],
|
|
25
|
+
expand: [wrapMixedContentStep],
|
|
26
|
+
nestedExpand: [wrapMixedContentStep],
|
|
27
|
+
layoutSection: [wrapMixedContentStep],
|
|
28
|
+
panel: [wrapMixedContentStep],
|
|
29
|
+
bulletList: [wrapIntoListStep],
|
|
30
|
+
orderedList: [wrapIntoListStep],
|
|
31
|
+
taskList: [wrapIntoListStep],
|
|
32
|
+
decisionList: [wrapIntoListStep]
|
|
33
|
+
},
|
|
34
|
+
heading: {
|
|
35
|
+
heading: [flattenStep, applyTargetTextTypeStep],
|
|
36
|
+
paragraph: [flattenStep, applyTargetTextTypeStep],
|
|
37
|
+
blockquote: [wrapMixedContentStep],
|
|
38
|
+
codeBlock: [wrapMixedContentStep],
|
|
39
|
+
expand: [wrapMixedContentStep],
|
|
40
|
+
nestedExpand: [wrapMixedContentStep],
|
|
41
|
+
layoutSection: [wrapMixedContentStep],
|
|
42
|
+
panel: [wrapMixedContentStep],
|
|
43
|
+
bulletList: [wrapIntoListStep],
|
|
44
|
+
orderedList: [wrapIntoListStep],
|
|
45
|
+
taskList: [wrapIntoListStep],
|
|
46
|
+
decisionList: [wrapIntoListStep]
|
|
47
|
+
},
|
|
48
|
+
panel: {
|
|
49
|
+
blockquote: [unwrapStep, wrapMixedContentStep],
|
|
50
|
+
codeBlock: [unwrapStep, wrapMixedContentStep],
|
|
51
|
+
expand: [unwrapStep, wrapStep],
|
|
52
|
+
nestedExpand: [unwrapStep, wrapStep],
|
|
53
|
+
layoutSection: [unwrapStep, wrapMixedContentStep],
|
|
54
|
+
paragraph: [unwrapStep]
|
|
55
|
+
},
|
|
56
|
+
expand: {
|
|
57
|
+
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
58
|
+
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
59
|
+
layoutSection: [unwrapExpandStep, wrapMixedContentStep],
|
|
60
|
+
nestedExpand: [unwrapExpandStep, wrapStep],
|
|
61
|
+
paragraph: [unwrapExpandStep]
|
|
62
|
+
},
|
|
63
|
+
nestedExpand: {
|
|
64
|
+
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
65
|
+
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
66
|
+
layoutSection: [unwrapExpandStep, wrapMixedContentStep],
|
|
67
|
+
paragraph: [unwrapExpandStep]
|
|
68
|
+
},
|
|
69
|
+
blockquote: {
|
|
70
|
+
expand: [wrapStep],
|
|
71
|
+
nestedExpand: [wrapStep],
|
|
72
|
+
layoutSection: [wrapMixedContentStep],
|
|
73
|
+
panel: [unwrapStep, wrapStep],
|
|
74
|
+
paragraph: [unwrapStep],
|
|
75
|
+
heading: [unwrapStep, applyTargetTextTypeStep],
|
|
76
|
+
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep]
|
|
77
|
+
},
|
|
78
|
+
layoutSection: {
|
|
79
|
+
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
80
|
+
expand: [unwrapLayoutStep, wrapStep],
|
|
81
|
+
nestedExpand: [unwrapLayoutStep, wrapStep],
|
|
82
|
+
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
83
|
+
paragraph: [unwrapLayoutStep]
|
|
84
|
+
},
|
|
85
|
+
codeBlock: {
|
|
86
|
+
blockquote: [wrapStep],
|
|
87
|
+
expand: [wrapStep],
|
|
88
|
+
nestedExpand: [wrapStep],
|
|
89
|
+
layoutSection: [wrapMixedContentStep],
|
|
90
|
+
panel: [wrapStep],
|
|
91
|
+
paragraph: [applyTargetTextTypeStep]
|
|
92
|
+
},
|
|
93
|
+
bulletList: {
|
|
94
|
+
orderedList: [listToListStep],
|
|
95
|
+
taskList: [listToListStep],
|
|
96
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
97
|
+
blockquote: [wrapStep],
|
|
98
|
+
expand: [wrapStep],
|
|
99
|
+
nestedExpand: [wrapStep],
|
|
100
|
+
layoutSection: [wrapMixedContentStep],
|
|
101
|
+
panel: [wrapStep],
|
|
102
|
+
paragraph: [flattenListStep, unwrapListStep, applyTargetTextTypeStep]
|
|
103
|
+
},
|
|
104
|
+
orderedList: {
|
|
105
|
+
bulletList: [listToListStep],
|
|
106
|
+
taskList: [listToListStep],
|
|
107
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
108
|
+
blockquote: [wrapStep],
|
|
109
|
+
expand: [wrapStep],
|
|
110
|
+
nestedExpand: [wrapStep],
|
|
111
|
+
layoutSection: [wrapMixedContentStep],
|
|
112
|
+
panel: [wrapStep],
|
|
113
|
+
paragraph: [flattenListStep, unwrapListStep, applyTargetTextTypeStep]
|
|
114
|
+
},
|
|
115
|
+
taskList: {
|
|
116
|
+
bulletList: [listToListStep],
|
|
117
|
+
orderedList: [listToListStep],
|
|
118
|
+
decisionList: [flattenListStep, listToDecisionListStep],
|
|
119
|
+
expand: [wrapStep],
|
|
120
|
+
nestedExpand: [wrapStep],
|
|
121
|
+
layoutSection: [wrapMixedContentStep],
|
|
122
|
+
panel: [wrapStep],
|
|
123
|
+
paragraph: [flattenListStep, unwrapListStep, applyTargetTextTypeStep]
|
|
124
|
+
},
|
|
125
|
+
table: {
|
|
126
|
+
expand: [wrapStep],
|
|
127
|
+
nestedExpand: [wrapStep],
|
|
128
|
+
layoutSection: [wrapMixedContentStep]
|
|
129
|
+
},
|
|
130
|
+
mediaSingle: {
|
|
131
|
+
blockquote: [wrapStep],
|
|
132
|
+
expand: [wrapStep],
|
|
133
|
+
nestedExpand: [wrapStep],
|
|
134
|
+
layoutSection: [wrapMixedContentStep],
|
|
135
|
+
panel: [wrapStep],
|
|
136
|
+
bulletList: [wrapIntoListStep],
|
|
137
|
+
orderedList: [wrapIntoListStep]
|
|
138
|
+
},
|
|
139
|
+
mediaGroup: {
|
|
140
|
+
blockquote: [wrapStep],
|
|
141
|
+
expand: [wrapStep],
|
|
142
|
+
nestedExpand: [wrapStep],
|
|
143
|
+
layoutSection: [wrapMixedContentStep],
|
|
144
|
+
panel: [wrapStep]
|
|
145
|
+
},
|
|
146
|
+
media: {
|
|
147
|
+
blockquote: [wrapStep],
|
|
148
|
+
codeBlock: [wrapStep],
|
|
149
|
+
expand: [wrapStep],
|
|
150
|
+
nestedExpand: [wrapStep],
|
|
151
|
+
layoutSection: [wrapStep],
|
|
152
|
+
panel: [wrapStep],
|
|
153
|
+
bulletList: [wrapIntoListStep],
|
|
154
|
+
orderedList: [wrapIntoListStep],
|
|
155
|
+
taskList: [wrapIntoListStep],
|
|
156
|
+
decisionList: [wrapIntoListStep]
|
|
157
|
+
},
|
|
158
|
+
decisionList: {
|
|
159
|
+
bulletList: [decisionListToListStep],
|
|
160
|
+
orderedList: [decisionListToListStep],
|
|
161
|
+
taskList: [decisionListToListStep],
|
|
162
|
+
blockquote: [unwrapListStep, wrapStep],
|
|
163
|
+
codeBlock: [unwrapListStep, wrapMixedContentStep],
|
|
164
|
+
expand: [wrapStep],
|
|
165
|
+
nestedExpand: [wrapStep],
|
|
166
|
+
layoutSection: [wrapMixedContentStep],
|
|
167
|
+
panel: [wrapStep],
|
|
168
|
+
paragraph: [flattenListStep, unwrapListStep, applyTargetTextTypeStep],
|
|
169
|
+
heading: [flattenListStep, unwrapListStep, applyTargetTextTypeStep]
|
|
170
|
+
},
|
|
171
|
+
blockCard: {
|
|
172
|
+
expand: [wrapStep],
|
|
173
|
+
nestedExpand: [wrapStep],
|
|
174
|
+
layoutSection: [wrapMixedContentStep],
|
|
175
|
+
panel: [wrapStep]
|
|
176
|
+
},
|
|
177
|
+
embedCard: {
|
|
178
|
+
expand: [wrapStep],
|
|
179
|
+
nestedExpand: [wrapStep],
|
|
180
|
+
layoutSection: [wrapMixedContentStep]
|
|
181
|
+
},
|
|
182
|
+
extension: {
|
|
183
|
+
blockquote: [wrapStep],
|
|
184
|
+
expand: [wrapStep],
|
|
185
|
+
nestedExpand: [wrapStep],
|
|
186
|
+
layoutSection: [wrapMixedContentStep],
|
|
187
|
+
panel: [wrapStep]
|
|
188
|
+
},
|
|
189
|
+
bodiedExtension: {
|
|
190
|
+
nestedExpand: [wrapStep],
|
|
191
|
+
layoutSection: [wrapMixedContentStep]
|
|
192
|
+
},
|
|
193
|
+
multiBodiedExtension: {
|
|
194
|
+
blockquote: [wrapStep],
|
|
195
|
+
codeBlock: [wrapStep],
|
|
196
|
+
expand: [wrapStep],
|
|
197
|
+
nestedExpand: [wrapStep],
|
|
198
|
+
layoutSection: [wrapStep],
|
|
199
|
+
panel: [wrapStep],
|
|
200
|
+
bulletList: [wrapIntoListStep],
|
|
201
|
+
orderedList: [wrapIntoListStep],
|
|
202
|
+
taskList: [wrapIntoListStep],
|
|
203
|
+
decisionList: [wrapIntoListStep]
|
|
204
|
+
},
|
|
205
|
+
multi: {
|
|
206
|
+
blockquote: [wrapMixedContentStep],
|
|
207
|
+
codeBlock: [wrapMixedContentStep],
|
|
208
|
+
expand: [wrapMixedContentStep],
|
|
209
|
+
nestedExpand: [wrapMixedContentStep],
|
|
210
|
+
layoutSection: [wrapMixedContentStep],
|
|
211
|
+
panel: [wrapMixedContentStep],
|
|
212
|
+
bulletList: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
213
|
+
orderedList: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
214
|
+
taskList: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
215
|
+
decisionList: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
216
|
+
paragraph: [convertEachNodeStep],
|
|
217
|
+
heading: [applyTargetTextTypeStep]
|
|
218
|
+
}
|
|
219
|
+
};
|
|
@@ -1,4 +1,44 @@
|
|
|
1
1
|
import { convertNodesToTargetType } from '../transform';
|
|
2
|
+
/**
|
|
3
|
+
* Handles the edge case where transforming multi-selection to decisionList results in
|
|
4
|
+
* all content breaking out (no valid children for the target). In this case, creates an empty
|
|
5
|
+
* decisionList to ensure the target type exists.
|
|
6
|
+
*
|
|
7
|
+
* Similar to handleEmptyContainerEdgeCase in wrapMixedContentStep, but specifically for
|
|
8
|
+
* multi-to-decisionList transformations where blockquotes break out.
|
|
9
|
+
*
|
|
10
|
+
* @param result - The current result nodes after processing
|
|
11
|
+
* @param hasCreatedDecisionList - Whether a decisionList was already created during processing
|
|
12
|
+
* @param targetNodeTypeName - The target node type name
|
|
13
|
+
* @param schema - The schema
|
|
14
|
+
* @returns The result nodes with an empty decisionList prepended if needed, or the original result
|
|
15
|
+
*/
|
|
16
|
+
const handleEmptyDecisionListEdgeCase = (result, hasCreatedDecisionList, targetNodeTypeName, schema) => {
|
|
17
|
+
// Only apply this edge case for decisionList target
|
|
18
|
+
if (targetNodeTypeName !== 'decisionList') {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If no decisionList was created but we have nodes in result, all content broke out
|
|
23
|
+
const allContentBrokeOut = !hasCreatedDecisionList && result.length > 0;
|
|
24
|
+
if (!allContentBrokeOut) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Create an empty decisionList
|
|
29
|
+
const decisionListType = schema.nodes.decisionList;
|
|
30
|
+
const decisionItemType = schema.nodes.decisionItem;
|
|
31
|
+
if (decisionListType && decisionItemType) {
|
|
32
|
+
const emptyDecisionItem = decisionItemType.createAndFill();
|
|
33
|
+
if (emptyDecisionItem) {
|
|
34
|
+
const emptyDecisionList = decisionListType.createAndFill({}, [emptyDecisionItem]);
|
|
35
|
+
if (emptyDecisionList) {
|
|
36
|
+
return [emptyDecisionList, ...result];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
2
42
|
export const convertEachNodeStep = (nodes, context) => {
|
|
3
43
|
const {
|
|
4
44
|
schema,
|
|
@@ -9,8 +49,15 @@ export const convertEachNodeStep = (nodes, context) => {
|
|
|
9
49
|
if (!targetNodeType) {
|
|
10
50
|
return nodes;
|
|
11
51
|
}
|
|
52
|
+
const blockquoteType = schema.nodes.blockquote;
|
|
12
53
|
const resultNodes = [];
|
|
54
|
+
let hasCreatedDecisionList = false;
|
|
13
55
|
for (const node of nodes) {
|
|
56
|
+
// Edge case: blockquotes should break out when transforming to decisionList
|
|
57
|
+
if (targetNodeTypeName === 'decisionList' && blockquoteType && node.type === blockquoteType) {
|
|
58
|
+
resultNodes.push(node);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
14
61
|
const transformedNodes = convertNodesToTargetType({
|
|
15
62
|
sourceNodes: [node],
|
|
16
63
|
targetNodeType,
|
|
@@ -20,9 +67,17 @@ export const convertEachNodeStep = (nodes, context) => {
|
|
|
20
67
|
});
|
|
21
68
|
if (transformedNodes.length > 0) {
|
|
22
69
|
resultNodes.push(...transformedNodes);
|
|
70
|
+
// Track if we created a decisionList
|
|
71
|
+
|
|
72
|
+
if (targetNodeTypeName === 'decisionList' && transformedNodes.some(n => n.type === targetNodeType)) {
|
|
73
|
+
hasCreatedDecisionList = true;
|
|
74
|
+
}
|
|
23
75
|
} else {
|
|
24
76
|
resultNodes.push(node);
|
|
25
77
|
}
|
|
26
78
|
}
|
|
27
|
-
|
|
79
|
+
|
|
80
|
+
// Handle edge case: if no decisionList was created, create an empty one
|
|
81
|
+
const finalResult = handleEmptyDecisionListEdgeCase(resultNodes, hasCreatedDecisionList, targetNodeTypeName, schema);
|
|
82
|
+
return finalResult;
|
|
28
83
|
};
|
|
@@ -1,238 +1,6 @@
|
|
|
1
1
|
import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { convertEachNodeStep } from './steps/convertEachNodeStep';
|
|
5
|
-
import { decisionListToListStep } from './steps/decisionListToListStep';
|
|
6
|
-
import { flattenListStep } from './steps/flattenListStep';
|
|
7
|
-
import { listToDecisionListStep } from './steps/listToDecisionListStep';
|
|
8
|
-
import { listToListStep } from './steps/listToListStep';
|
|
9
|
-
import { mergeNeighbourListsStep } from './steps/mergeNeighbourListsStep';
|
|
10
|
-
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
11
|
-
import { unwrapListStep } from './steps/unwrapListStep';
|
|
12
|
-
import { wrapBlockquoteToDecisionListStep } from './steps/wrapBlockquoteToDecisionListStep';
|
|
13
|
-
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
14
|
-
import { getNodeName, NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
15
|
-
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
16
|
-
import { unwrapStep } from './unwrapStep';
|
|
17
|
-
import { wrapIntoListStep } from './wrapIntoListStep';
|
|
18
|
-
import { wrapStep } from './wrapStep';
|
|
19
|
-
|
|
20
|
-
// Transform steps for combinations of node categories (block/container/list/text)
|
|
21
|
-
const TRANSFORM_STEPS = {
|
|
22
|
-
atomic: {
|
|
23
|
-
atomic: undefined,
|
|
24
|
-
container: [wrapStep],
|
|
25
|
-
list: [wrapIntoListStep],
|
|
26
|
-
text: undefined,
|
|
27
|
-
multi: undefined
|
|
28
|
-
},
|
|
29
|
-
container: {
|
|
30
|
-
atomic: undefined,
|
|
31
|
-
container: [unwrapStep, wrapStep],
|
|
32
|
-
list: undefined,
|
|
33
|
-
text: [unwrapStep],
|
|
34
|
-
multi: undefined
|
|
35
|
-
},
|
|
36
|
-
list: {
|
|
37
|
-
atomic: undefined,
|
|
38
|
-
container: [wrapStep],
|
|
39
|
-
list: [listToListStep],
|
|
40
|
-
text: [flattenListStep, unwrapListStep, applyTargetTextTypeStep],
|
|
41
|
-
multi: undefined
|
|
42
|
-
},
|
|
43
|
-
text: {
|
|
44
|
-
atomic: undefined,
|
|
45
|
-
container: [wrapMixedContentStep],
|
|
46
|
-
list: [wrapIntoListStep],
|
|
47
|
-
text: [flattenStep, applyTargetTextTypeStep],
|
|
48
|
-
multi: undefined
|
|
49
|
-
},
|
|
50
|
-
multi: {
|
|
51
|
-
atomic: undefined,
|
|
52
|
-
container: [wrapMixedContentStep],
|
|
53
|
-
list: [convertEachNodeStep, mergeNeighbourListsStep],
|
|
54
|
-
text: [convertEachNodeStep],
|
|
55
|
-
multi: undefined
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Transform steps for specific pairs of node types that cannot be processed
|
|
60
|
-
// using generic rules/steps from TRANSFORM_STEPS.
|
|
61
|
-
// Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
|
|
62
|
-
const TRANSFORM_STEPS_OVERRIDE = {
|
|
63
|
-
paragraph: {
|
|
64
|
-
paragraph: null
|
|
65
|
-
},
|
|
66
|
-
heading: {},
|
|
67
|
-
panel: {
|
|
68
|
-
panel: null,
|
|
69
|
-
layoutSection: [unwrapStep, wrapMixedContentStep],
|
|
70
|
-
codeBlock: [unwrapStep, wrapMixedContentStep],
|
|
71
|
-
blockquote: [unwrapStep, wrapMixedContentStep],
|
|
72
|
-
taskList: null,
|
|
73
|
-
bulletList: null,
|
|
74
|
-
orderedList: null,
|
|
75
|
-
heading: null
|
|
76
|
-
},
|
|
77
|
-
expand: {
|
|
78
|
-
expand: null,
|
|
79
|
-
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
80
|
-
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
81
|
-
layoutSection: [unwrapExpandStep, wrapMixedContentStep],
|
|
82
|
-
paragraph: [unwrapExpandStep],
|
|
83
|
-
codeBlock: null,
|
|
84
|
-
heading: null
|
|
85
|
-
},
|
|
86
|
-
nestedExpand: {
|
|
87
|
-
expand: null,
|
|
88
|
-
nestedExpand: null,
|
|
89
|
-
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
90
|
-
blockquote: [unwrapExpandStep, wrapMixedContentStep],
|
|
91
|
-
paragraph: [unwrapExpandStep],
|
|
92
|
-
codeBlock: null,
|
|
93
|
-
heading: null
|
|
94
|
-
},
|
|
95
|
-
blockquote: {
|
|
96
|
-
blockquote: null,
|
|
97
|
-
expand: [wrapStep],
|
|
98
|
-
nestedExpand: [wrapStep],
|
|
99
|
-
layoutSection: [wrapMixedContentStep],
|
|
100
|
-
codeBlock: null,
|
|
101
|
-
decisionList: [unwrapStep, wrapBlockquoteToDecisionListStep],
|
|
102
|
-
paragraph: [unwrapStep],
|
|
103
|
-
heading: [unwrapStep, applyTargetTextTypeStep]
|
|
104
|
-
},
|
|
105
|
-
layoutSection: {
|
|
106
|
-
layoutSection: null,
|
|
107
|
-
blockquote: [unwrapLayoutStep, wrapMixedContentStep],
|
|
108
|
-
expand: [unwrapLayoutStep, wrapStep],
|
|
109
|
-
panel: [unwrapLayoutStep, wrapMixedContentStep],
|
|
110
|
-
codeBlock: null,
|
|
111
|
-
paragraph: [unwrapLayoutStep],
|
|
112
|
-
heading: null
|
|
113
|
-
},
|
|
114
|
-
codeBlock: {
|
|
115
|
-
codeBlock: null,
|
|
116
|
-
blockquote: [wrapStep],
|
|
117
|
-
expand: [wrapStep],
|
|
118
|
-
nestedExpand: [wrapStep],
|
|
119
|
-
layoutSection: [wrapMixedContentStep],
|
|
120
|
-
panel: [wrapStep],
|
|
121
|
-
paragraph: [applyTargetTextTypeStep],
|
|
122
|
-
heading: null
|
|
123
|
-
},
|
|
124
|
-
bulletList: {
|
|
125
|
-
bulletList: null,
|
|
126
|
-
codeBlock: null,
|
|
127
|
-
layoutSection: [wrapMixedContentStep],
|
|
128
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
129
|
-
heading: null
|
|
130
|
-
},
|
|
131
|
-
orderedList: {
|
|
132
|
-
orderedList: null,
|
|
133
|
-
codeBlock: null,
|
|
134
|
-
layoutSection: [wrapMixedContentStep],
|
|
135
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
136
|
-
heading: null
|
|
137
|
-
},
|
|
138
|
-
taskList: {
|
|
139
|
-
blockquote: null,
|
|
140
|
-
codeBlock: null,
|
|
141
|
-
layoutSection: [wrapMixedContentStep],
|
|
142
|
-
decisionList: [flattenListStep, listToDecisionListStep],
|
|
143
|
-
heading: null,
|
|
144
|
-
taskList: null
|
|
145
|
-
},
|
|
146
|
-
table: {
|
|
147
|
-
layoutSection: [wrapMixedContentStep],
|
|
148
|
-
blockquote: null,
|
|
149
|
-
panel: null,
|
|
150
|
-
codeBlock: null,
|
|
151
|
-
orderedList: null,
|
|
152
|
-
bulletList: null,
|
|
153
|
-
taskList: null,
|
|
154
|
-
decisionList: null
|
|
155
|
-
},
|
|
156
|
-
mediaSingle: {
|
|
157
|
-
layoutSection: [wrapMixedContentStep],
|
|
158
|
-
codeBlock: null,
|
|
159
|
-
decisionList: null,
|
|
160
|
-
taskList: null
|
|
161
|
-
},
|
|
162
|
-
mediaGroup: {
|
|
163
|
-
layoutSection: [wrapMixedContentStep],
|
|
164
|
-
codeBlock: null,
|
|
165
|
-
decisionList: null,
|
|
166
|
-
bulletList: null,
|
|
167
|
-
orderedList: null,
|
|
168
|
-
taskList: null
|
|
169
|
-
},
|
|
170
|
-
decisionList: {
|
|
171
|
-
decisionList: null,
|
|
172
|
-
bulletList: [decisionListToListStep],
|
|
173
|
-
orderedList: [decisionListToListStep],
|
|
174
|
-
taskList: [decisionListToListStep],
|
|
175
|
-
layoutSection: [wrapMixedContentStep],
|
|
176
|
-
blockquote: [unwrapListStep, wrapStep],
|
|
177
|
-
codeBlock: [unwrapListStep, wrapMixedContentStep]
|
|
178
|
-
},
|
|
179
|
-
blockCard: {
|
|
180
|
-
layoutSection: [wrapMixedContentStep],
|
|
181
|
-
blockquote: null,
|
|
182
|
-
codeBlock: null,
|
|
183
|
-
orderedList: null,
|
|
184
|
-
bulletList: null,
|
|
185
|
-
taskList: null,
|
|
186
|
-
decisionList: null
|
|
187
|
-
},
|
|
188
|
-
embedCard: {
|
|
189
|
-
layoutSection: [wrapMixedContentStep],
|
|
190
|
-
blockquote: null,
|
|
191
|
-
panel: null,
|
|
192
|
-
codeBlock: null,
|
|
193
|
-
orderedList: null,
|
|
194
|
-
bulletList: null,
|
|
195
|
-
taskList: null,
|
|
196
|
-
decisionList: null
|
|
197
|
-
},
|
|
198
|
-
extension: {
|
|
199
|
-
layoutSection: [wrapMixedContentStep],
|
|
200
|
-
codeBlock: null,
|
|
201
|
-
decisionList: null,
|
|
202
|
-
taskList: null,
|
|
203
|
-
orderedList: null,
|
|
204
|
-
bulletList: null
|
|
205
|
-
},
|
|
206
|
-
bodiedExtension: {
|
|
207
|
-
layoutSection: [wrapMixedContentStep],
|
|
208
|
-
blockquote: null,
|
|
209
|
-
expand: null,
|
|
210
|
-
panel: null,
|
|
211
|
-
codeBlock: null,
|
|
212
|
-
orderedList: null,
|
|
213
|
-
bulletList: null,
|
|
214
|
-
taskList: null,
|
|
215
|
-
decisionList: null
|
|
216
|
-
},
|
|
217
|
-
multi: {
|
|
218
|
-
heading: [applyTargetTextTypeStep]
|
|
219
|
-
// Similar to heading, all structures are kept as is
|
|
220
|
-
// EG: transformed: other lists, paragarph, headings
|
|
221
|
-
// eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
|
|
222
|
-
// decisionList: [],
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const getTransformStepsForNodeTypes = (selectedNodeTypeName, targetNodeTypeName) => {
|
|
226
|
-
var _TRANSFORM_STEPS_OVER;
|
|
227
|
-
const fromCategory = NODE_CATEGORY_BY_TYPE[selectedNodeTypeName];
|
|
228
|
-
const toCategory = NODE_CATEGORY_BY_TYPE[targetNodeTypeName];
|
|
229
|
-
const overrideSteps = (_TRANSFORM_STEPS_OVER = TRANSFORM_STEPS_OVERRIDE[selectedNodeTypeName]) === null || _TRANSFORM_STEPS_OVER === void 0 ? void 0 : _TRANSFORM_STEPS_OVER[targetNodeTypeName];
|
|
230
|
-
if (overrideSteps === null) {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
const steps = overrideSteps !== null && overrideSteps !== void 0 ? overrideSteps : TRANSFORM_STEPS[fromCategory][toCategory];
|
|
234
|
-
return steps;
|
|
235
|
-
};
|
|
2
|
+
import { TRANSFORMATION_MATRIX } from './TRANSFORMATION_MATRIX';
|
|
3
|
+
import { getNodeName, toNodeTypeValue } from './types';
|
|
236
4
|
/**
|
|
237
5
|
* Convert a list of nodes to a target node type.
|
|
238
6
|
* If no steps are found, the source nodes are returned unchanged.
|
|
@@ -266,7 +34,7 @@ export const convertNodesToTargetType = ({
|
|
|
266
34
|
if (!selectedNodeTypeName || !targetNodeTypeName) {
|
|
267
35
|
return sourceNodes;
|
|
268
36
|
}
|
|
269
|
-
const steps =
|
|
37
|
+
const steps = TRANSFORMATION_MATRIX[selectedNodeTypeName][targetNodeTypeName];
|
|
270
38
|
const context = {
|
|
271
39
|
// sourceNode is incorrect now - what to do here?
|
|
272
40
|
fromNode: sourceNode,
|
|
@@ -282,9 +50,6 @@ export const convertNodesToTargetType = ({
|
|
|
282
50
|
}, sourceNodes);
|
|
283
51
|
};
|
|
284
52
|
export const isTransformDisabledBasedOnStepsConfig = (selectedNodeType, targetNodeType) => {
|
|
285
|
-
const steps =
|
|
286
|
-
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
return false;
|
|
53
|
+
const steps = TRANSFORMATION_MATRIX[selectedNodeType][targetNodeType];
|
|
54
|
+
return !steps || steps.length === 0;
|
|
290
55
|
};
|