@atlaskit/editor-plugin-block-menu 5.1.5 → 5.1.7
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 +15 -0
- package/dist/cjs/editor-commands/transform-node-utils/flattenListStep.js +9 -32
- package/dist/cjs/editor-commands/transform-node-utils/steps/unwrapLayoutStep.js +38 -0
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +24 -4
- package/dist/cjs/editor-commands/transform-node-utils/unwrapExpandStep.js +6 -7
- package/dist/cjs/editor-commands/transform-node-utils/unwrapListStep.js +16 -1
- package/dist/cjs/editor-commands/transform-node-utils/utils.js +30 -1
- package/dist/cjs/editor-commands/transform-node-utils/wrapStep.js +0 -1
- package/dist/cjs/editor-commands/transformNode.js +6 -6
- package/dist/cjs/ui/utils/suggested-items-rank.js +107 -0
- package/dist/es2019/editor-commands/transform-node-utils/flattenListStep.js +9 -32
- package/dist/es2019/editor-commands/transform-node-utils/steps/unwrapLayoutStep.js +30 -0
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +24 -4
- package/dist/es2019/editor-commands/transform-node-utils/unwrapExpandStep.js +8 -7
- package/dist/es2019/editor-commands/transform-node-utils/unwrapListStep.js +16 -1
- package/dist/es2019/editor-commands/transform-node-utils/utils.js +29 -1
- package/dist/es2019/editor-commands/transform-node-utils/wrapStep.js +0 -1
- package/dist/es2019/editor-commands/transformNode.js +2 -2
- package/dist/es2019/ui/utils/suggested-items-rank.js +223 -0
- package/dist/esm/editor-commands/transform-node-utils/flattenListStep.js +9 -32
- package/dist/esm/editor-commands/transform-node-utils/steps/unwrapLayoutStep.js +31 -0
- package/dist/esm/editor-commands/transform-node-utils/transform.js +24 -4
- package/dist/esm/editor-commands/transform-node-utils/unwrapExpandStep.js +7 -7
- package/dist/esm/editor-commands/transform-node-utils/unwrapListStep.js +16 -1
- package/dist/esm/editor-commands/transform-node-utils/utils.js +30 -1
- package/dist/esm/editor-commands/transform-node-utils/wrapStep.js +0 -1
- package/dist/esm/editor-commands/transformNode.js +4 -4
- package/dist/esm/ui/utils/suggested-items-rank.js +101 -0
- package/dist/types/editor-commands/transform-node-utils/flattenListStep.d.ts +0 -18
- package/dist/types/editor-commands/transform-node-utils/steps/unwrapLayoutStep.d.ts +14 -0
- package/dist/types/editor-commands/transform-node-utils/unwrapListStep.d.ts +16 -1
- package/dist/types/editor-commands/transform-node-utils/utils.d.ts +12 -0
- package/dist/types/ui/utils/suggested-items-rank.d.ts +81 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/flattenListStep.d.ts +0 -18
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/unwrapLayoutStep.d.ts +14 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapListStep.d.ts +16 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +12 -0
- package/dist/types-ts4.5/ui/utils/suggested-items-rank.d.ts +81 -0
- package/package.json +4 -4
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Given an array of nodes,
|
|
2
|
+
* Given an array of nodes, processes each list removing all parent list nodes and
|
|
3
|
+
* just returning their child contents.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* Input:
|
|
7
|
+
* - bulletList
|
|
8
|
+
* - listItem "1"
|
|
9
|
+
* - paragraph "1"
|
|
10
|
+
* - listItem "2"
|
|
11
|
+
* - paragraph "2"
|
|
12
|
+
*
|
|
13
|
+
* Output:
|
|
14
|
+
* - paragraph "1"
|
|
15
|
+
* - paragraph "2"
|
|
16
|
+
*
|
|
3
17
|
* @param nodes
|
|
18
|
+
* @param context
|
|
4
19
|
* @returns
|
|
5
20
|
*/
|
|
6
21
|
export const unwrapListStep = (nodes, context) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
1
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { findParentNodeOfType, hasParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
3
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
4
5
|
export const getSelectedNode = selection => {
|
|
5
6
|
if (selection instanceof NodeSelection) {
|
|
@@ -49,4 +50,31 @@ export const getTargetNodeTypeNameInContext = (nodeTypeName, isNested) => {
|
|
|
49
50
|
return 'nestedExpand';
|
|
50
51
|
}
|
|
51
52
|
return nodeTypeName;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Use common expandToBlockRange function, but account for edge cases with lists.
|
|
57
|
+
*
|
|
58
|
+
* @param selection
|
|
59
|
+
* @param schema
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export const expandSelectionToBlockRange = (selection, schema) => {
|
|
63
|
+
const isListInSelection = hasParentNode(node => node.type === schema.nodes.bulletList || node.type === schema.nodes.orderedList)(selection);
|
|
64
|
+
const {
|
|
65
|
+
$from,
|
|
66
|
+
$to
|
|
67
|
+
} = expandToBlockRange(selection.$from, selection.$to, node => {
|
|
68
|
+
if (!isListInSelection) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (node.type === schema.nodes.bulletList || node.type === schema.nodes.orderedList) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
$from,
|
|
78
|
+
$to
|
|
79
|
+
};
|
|
52
80
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import { isNestedNode } from '../ui/utils/isNestedNode';
|
|
4
3
|
import { getOutputNodes } from './transform-node-utils/transform';
|
|
4
|
+
import { expandSelectionToBlockRange } from './transform-node-utils/utils';
|
|
5
5
|
import { isListNode } from './transforms/utils';
|
|
6
6
|
export const transformNode = api =>
|
|
7
7
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -17,7 +17,7 @@ export const transformNode = api =>
|
|
|
17
17
|
const {
|
|
18
18
|
$from,
|
|
19
19
|
$to
|
|
20
|
-
} =
|
|
20
|
+
} = expandSelectionToBlockRange(preservedSelection, tr.doc.type.schema);
|
|
21
21
|
const isNested = isNestedNode(preservedSelection, '');
|
|
22
22
|
const selectedParent = $from.parent;
|
|
23
23
|
let fragment = Fragment.empty;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suggested transformations mapping for each block type.
|
|
3
|
+
* Based on the Block Menu Compatibility Matrix:
|
|
4
|
+
* https://hello.atlassian.net/wiki/spaces/egcuc/pages/5868774224/Block+Menu+Compatibility+Matrix#Suggested-for-each-block-type
|
|
5
|
+
*
|
|
6
|
+
* This mapping defines which transform items should appear in the TRANSFORM_SUGGESTED_MENU_SECTION
|
|
7
|
+
* for each block type, ranked by priority (lower rank = higher priority).
|
|
8
|
+
*
|
|
9
|
+
* Structure:
|
|
10
|
+
* {
|
|
11
|
+
* [sourceNodeType]: {
|
|
12
|
+
* [targetMenuItemKey]: rank
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { TRANSFORM_STRUCTURE_PANEL_MENU_ITEM, TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM, TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM, TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM, TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM, TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM, TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM, TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM, TRANSFORM_HEADINGS_H2_MENU_ITEM, TRANSFORM_HEADINGS_H3_MENU_ITEM, TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM } from '@atlaskit/editor-common/block-menu';
|
|
18
|
+
/**
|
|
19
|
+
* Node type keys that map to ProseMirror node types from the ADF schema.
|
|
20
|
+
* These values must match the NodeTypeName type.
|
|
21
|
+
*
|
|
22
|
+
* TypeScript will enforce that all values are valid NodeTypeName values.
|
|
23
|
+
* If a new node type is added, it must be added to NodeTypeName first.
|
|
24
|
+
*
|
|
25
|
+
* Reference: packages/editor/editor-plugin-block-menu/src/editor-commands/transform-node-utils/types.ts
|
|
26
|
+
*
|
|
27
|
+
* Note: 'heading' represents all heading levels (1-6) as a single node type.
|
|
28
|
+
* The specific level is determined by the node's `attrs.level` property at runtime.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Usage:
|
|
32
|
+
* const nodeType = BLOCK_MENU_NODE_TYPES.PARAGRAPH; // Type: "paragraph"
|
|
33
|
+
*/
|
|
34
|
+
export const BLOCK_MENU_NODE_TYPES = {
|
|
35
|
+
PARAGRAPH: 'paragraph',
|
|
36
|
+
EXPAND: 'expand',
|
|
37
|
+
BLOCKQUOTE: 'blockquote',
|
|
38
|
+
LAYOUT_SECTION: 'layoutSection',
|
|
39
|
+
PANEL: 'panel',
|
|
40
|
+
CODE_BLOCK: 'codeBlock',
|
|
41
|
+
DECISION: 'decisionList',
|
|
42
|
+
BULLET_LIST: 'bulletList',
|
|
43
|
+
ORDERED_LIST: 'orderedList',
|
|
44
|
+
HEADING: 'heading',
|
|
45
|
+
TASK_LIST: 'taskList',
|
|
46
|
+
MEDIA_SINGLE: 'mediaSingle',
|
|
47
|
+
EXTENSION: 'extension',
|
|
48
|
+
BODIED_EXTENSION: 'bodiedExtension',
|
|
49
|
+
BLOCK_CARD: 'blockCard',
|
|
50
|
+
EMBED_CARD: 'embedCard',
|
|
51
|
+
TABLE: 'table'
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Type for node type values extracted from BLOCK_MENU_NODE_TYPES
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Type for the suggested items rank mapping
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Mapping of source node types to suggested transformation menu items with their ranks.
|
|
64
|
+
* Lower rank number = higher priority in the suggested menu section.
|
|
65
|
+
*/
|
|
66
|
+
export const TRANSFORM_SUGGESTED_ITEMS_RANK = {
|
|
67
|
+
// Paragraph suggestions
|
|
68
|
+
[BLOCK_MENU_NODE_TYPES.PARAGRAPH]: {
|
|
69
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
70
|
+
// Turn into Panel
|
|
71
|
+
[TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 200,
|
|
72
|
+
// Turn into Heading 2
|
|
73
|
+
[TRANSFORM_HEADINGS_H3_MENU_ITEM.key]: 300 // Turn into Heading 3
|
|
74
|
+
},
|
|
75
|
+
// Expand suggestions
|
|
76
|
+
[BLOCK_MENU_NODE_TYPES.EXPAND]: {
|
|
77
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
78
|
+
// Turn into Panel (wrap content)
|
|
79
|
+
[TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
|
|
80
|
+
// Turn into Layout
|
|
81
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
|
|
82
|
+
},
|
|
83
|
+
// Quote block (blockquote) suggestions
|
|
84
|
+
[BLOCK_MENU_NODE_TYPES.BLOCKQUOTE]: {
|
|
85
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
86
|
+
// Turn into Panel
|
|
87
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
|
|
88
|
+
// Turn into Paragraph
|
|
89
|
+
[TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 300 // Turn into Layout
|
|
90
|
+
},
|
|
91
|
+
// Layout suggestions
|
|
92
|
+
[BLOCK_MENU_NODE_TYPES.LAYOUT_SECTION]: {
|
|
93
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
94
|
+
// Wrap layout in panel
|
|
95
|
+
[TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 200,
|
|
96
|
+
// Make layout collapsible
|
|
97
|
+
[TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 300 // doesn't meet compatibility matrix, needs to be updated
|
|
98
|
+
},
|
|
99
|
+
// Panel suggestions
|
|
100
|
+
[BLOCK_MENU_NODE_TYPES.PANEL]: {
|
|
101
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
|
|
102
|
+
// Turn into Paragraph
|
|
103
|
+
[TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key]: 200,
|
|
104
|
+
// Turn into Blockquote
|
|
105
|
+
[TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300 // Turn into Code Block
|
|
106
|
+
},
|
|
107
|
+
// Code block suggestions
|
|
108
|
+
[BLOCK_MENU_NODE_TYPES.CODE_BLOCK]: {
|
|
109
|
+
[TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 100,
|
|
110
|
+
// Turn into Expand
|
|
111
|
+
[TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
|
|
112
|
+
// Turn into Layout
|
|
113
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300 // Turn into Panel
|
|
114
|
+
},
|
|
115
|
+
// Decision suggestions
|
|
116
|
+
[BLOCK_MENU_NODE_TYPES.DECISION]: {
|
|
117
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
118
|
+
// Wrap in Panel (Decision style)
|
|
119
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
|
|
120
|
+
// Turn into Paragraph
|
|
121
|
+
[TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]: 300 // Convert to Task List
|
|
122
|
+
},
|
|
123
|
+
// Bulleted list suggestions
|
|
124
|
+
[BLOCK_MENU_NODE_TYPES.BULLET_LIST]: {
|
|
125
|
+
[TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key]: 100,
|
|
126
|
+
// Turn into Numbered list
|
|
127
|
+
[TRANSFORM_STRUCTURE_QUOTE_MENU_ITEM.key]: 200,
|
|
128
|
+
// Turn into Blockquote
|
|
129
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
|
|
130
|
+
},
|
|
131
|
+
// Numbered list (ordered list) suggestions
|
|
132
|
+
[BLOCK_MENU_NODE_TYPES.ORDERED_LIST]: {
|
|
133
|
+
[TRANSFORM_STRUCTURE_BULLETED_LIST_MENU_ITEM.key]: 100,
|
|
134
|
+
// Turn into Bulleted list
|
|
135
|
+
[TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]: 200,
|
|
136
|
+
// Turn into Task List
|
|
137
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // Turn into Paragraph
|
|
138
|
+
},
|
|
139
|
+
// Heading suggestions
|
|
140
|
+
// Note: For headings, the specific heading level would need to be determined at runtime
|
|
141
|
+
// This provides a general mapping, but actual implementation should consider current heading level
|
|
142
|
+
[BLOCK_MENU_NODE_TYPES.HEADING]: {
|
|
143
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
|
|
144
|
+
// Turn into Paragraph
|
|
145
|
+
[TRANSFORM_HEADINGS_H2_MENU_ITEM.key]: 200,
|
|
146
|
+
// Turn into Heading 2
|
|
147
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 300 // Wrap in Panel
|
|
148
|
+
},
|
|
149
|
+
// Task list suggestions
|
|
150
|
+
[BLOCK_MENU_NODE_TYPES.TASK_LIST]: {
|
|
151
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 100,
|
|
152
|
+
// Turn into Paragraph
|
|
153
|
+
[TRANSFORM_STRUCTURE_NUMBERED_LIST_MENU_ITEM.key]: 200,
|
|
154
|
+
// Turn into Ordered list
|
|
155
|
+
[TRANSFORM_STRUCTURE_CODE_BLOCK_MENU_ITEM.key]: 300 // Turn into Code Block (for technical TODOs)
|
|
156
|
+
},
|
|
157
|
+
// Media (mediaSingle) suggestions
|
|
158
|
+
[BLOCK_MENU_NODE_TYPES.MEDIA_SINGLE]: {
|
|
159
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
160
|
+
// Wrap in Panel
|
|
161
|
+
[TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200,
|
|
162
|
+
// Place into Layout
|
|
163
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 300 // doesn't meet compatibility matrix, needs to be updated
|
|
164
|
+
},
|
|
165
|
+
// Extension (app/macro) suggestions
|
|
166
|
+
[BLOCK_MENU_NODE_TYPES.EXTENSION]: {
|
|
167
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
168
|
+
// Wrap in Panel
|
|
169
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
|
|
170
|
+
// doesn't meet compatibility matrix, needs to be updated
|
|
171
|
+
[TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300 // Collapse in Expand
|
|
172
|
+
},
|
|
173
|
+
// Bodied Extension suggestions (same as Extension)
|
|
174
|
+
[BLOCK_MENU_NODE_TYPES.BODIED_EXTENSION]: {
|
|
175
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
176
|
+
// Wrap in Panel
|
|
177
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200,
|
|
178
|
+
// doesn't meet compatibility matrix, needs to be updated
|
|
179
|
+
[TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 300 // Collapse in Expand
|
|
180
|
+
},
|
|
181
|
+
// Smart link Card suggestions
|
|
182
|
+
[BLOCK_MENU_NODE_TYPES.BLOCK_CARD]: {
|
|
183
|
+
// Note: Smart link card conversion would be rank 100 (demote to card)
|
|
184
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
185
|
+
// Wrap in Panel
|
|
186
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200 // doesn't meet compatibility matrix, needs to be updated
|
|
187
|
+
},
|
|
188
|
+
// Smart link Embed suggestions
|
|
189
|
+
[BLOCK_MENU_NODE_TYPES.EMBED_CARD]: {
|
|
190
|
+
// Note: Smart link embed conversion would be rank 100 (promote to embed)
|
|
191
|
+
[TRANSFORM_STRUCTURE_PANEL_MENU_ITEM.key]: 100,
|
|
192
|
+
// Wrap in Panel
|
|
193
|
+
[TRANSFORM_STRUCTURE_PARAGRAPH_MENU_ITEM.key]: 200 // doesn't meet compatibility matrix, needs to be updated
|
|
194
|
+
},
|
|
195
|
+
// Table suggestions
|
|
196
|
+
[BLOCK_MENU_NODE_TYPES.TABLE]: {
|
|
197
|
+
[TRANSFORM_STRUCTURE_EXPAND_MENU_ITEM.key]: 100,
|
|
198
|
+
// Turn into Expand
|
|
199
|
+
[TRANSFORM_STRUCTURE_LAYOUT_MENU_ITEM.key]: 200 // Turn into Layout
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Get suggested menu items for a given node type
|
|
205
|
+
* @param nodeType - The source node type (e.g., 'paragraph', 'heading')
|
|
206
|
+
* @returns Object mapping menu item keys to their ranks, or undefined if no suggestions
|
|
207
|
+
*/
|
|
208
|
+
export const getSuggestedItemsForNodeType = nodeType => {
|
|
209
|
+
return TRANSFORM_SUGGESTED_ITEMS_RANK[nodeType];
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get sorted suggested menu item keys for a given node type
|
|
214
|
+
* @param nodeType - The source node type
|
|
215
|
+
* @returns Array of menu item keys sorted by rank (highest priority first)
|
|
216
|
+
*/
|
|
217
|
+
export const getSortedSuggestedItems = nodeType => {
|
|
218
|
+
const suggestions = getSuggestedItemsForNodeType(nodeType);
|
|
219
|
+
if (!suggestions) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
return Object.entries(suggestions).sort(([, rankA], [, rankB]) => rankA - rankB).map(([key]) => key);
|
|
223
|
+
};
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes) {
|
|
2
|
+
var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes, schema) {
|
|
3
3
|
var items = [];
|
|
4
|
+
var paragraph = schema.nodes.paragraph;
|
|
4
5
|
var _extract = function extract(currentNode) {
|
|
5
6
|
currentNode.forEach(function (child) {
|
|
6
|
-
// list item -> take content without nested lists, then recurse into nested lists
|
|
7
7
|
if (itemTypes.some(function (type) {
|
|
8
8
|
return child.type === type;
|
|
9
9
|
})) {
|
|
10
|
-
// Filter out nested list nodes from the list item's content
|
|
11
10
|
var contentWithoutNestedLists = [];
|
|
12
11
|
var nestedLists = [];
|
|
13
12
|
child.forEach(function (grandChild) {
|
|
14
13
|
if (listTypes.some(function (type) {
|
|
15
14
|
return grandChild.type === type;
|
|
16
15
|
})) {
|
|
17
|
-
// This is a nested list - collect it for later processing
|
|
18
16
|
nestedLists.push(grandChild);
|
|
19
17
|
} else {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (grandChild.isText) {
|
|
19
|
+
contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
|
|
20
|
+
} else {
|
|
21
|
+
contentWithoutNestedLists.push(grandChild);
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
// Add the list item with only its non-list content
|
|
26
25
|
items.push(child.copy(Fragment.from(contentWithoutNestedLists)));
|
|
27
|
-
|
|
28
|
-
// Now process nested lists to maintain document order
|
|
29
26
|
nestedLists.forEach(function (nestedList) {
|
|
30
27
|
_extract(nestedList);
|
|
31
28
|
});
|
|
32
|
-
}
|
|
33
|
-
// lists -> keep operating
|
|
34
|
-
else if (listTypes.some(function (type) {
|
|
29
|
+
} else if (listTypes.some(function (type) {
|
|
35
30
|
return child.type === type;
|
|
36
31
|
})) {
|
|
37
32
|
_extract(child);
|
|
@@ -47,24 +42,6 @@ var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes)
|
|
|
47
42
|
* to it's first ancestor list, maintaining document order.
|
|
48
43
|
*
|
|
49
44
|
* @example
|
|
50
|
-
* Input:
|
|
51
|
-
* - bulletList
|
|
52
|
-
* - listItem "A"
|
|
53
|
-
* - listItem "B"
|
|
54
|
-
* - bulletList
|
|
55
|
-
* - listItem "C"
|
|
56
|
-
* - listItem "D"
|
|
57
|
-
* - listItem "E"
|
|
58
|
-
*
|
|
59
|
-
* Output:
|
|
60
|
-
* - bulletList
|
|
61
|
-
* - listItem "A"
|
|
62
|
-
* - listItem "B"
|
|
63
|
-
* - listItem "C"
|
|
64
|
-
* - listItem "D"
|
|
65
|
-
* - listItem "E"
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
45
|
* Input (deeply nested):
|
|
69
46
|
* - bulletList
|
|
70
47
|
* - listItem "1"
|
|
@@ -95,7 +72,7 @@ export var flattenListStep = function flattenListStep(nodes, context) {
|
|
|
95
72
|
if (listTypes.some(function (type) {
|
|
96
73
|
return node.type === type;
|
|
97
74
|
})) {
|
|
98
|
-
return node.copy(Fragment.from(extractNestedLists(node, listTypes, [context.schema.nodes.listItem, context.schema.nodes.taskItem])));
|
|
75
|
+
return node.copy(Fragment.from(extractNestedLists(node, listTypes, [context.schema.nodes.listItem, context.schema.nodes.taskItem], context.schema)));
|
|
99
76
|
}
|
|
100
77
|
return node;
|
|
101
78
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps a layoutSection node, extracting content from all columns.
|
|
4
|
+
* Works with any number of columns (2, 3, etc.).
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
* layoutSection(
|
|
8
|
+
* layoutColumn(p('a'), p('b')),
|
|
9
|
+
* layoutColumn(p('c')),
|
|
10
|
+
* layoutColumn(p('d'))
|
|
11
|
+
* )
|
|
12
|
+
* → [p('a'), p('b'), p('c'), p('d')]
|
|
13
|
+
*/
|
|
14
|
+
export var unwrapLayoutStep = function unwrapLayoutStep(nodes) {
|
|
15
|
+
var outputNodes = [];
|
|
16
|
+
nodes.forEach(function (node) {
|
|
17
|
+
var isLayoutSection = node.type.name === 'layoutSection';
|
|
18
|
+
if (isLayoutSection) {
|
|
19
|
+
node.children.forEach(function (column) {
|
|
20
|
+
var isLayoutColumn = column.type.name === 'layoutColumn';
|
|
21
|
+
if (isLayoutColumn) {
|
|
22
|
+
outputNodes.push.apply(outputNodes, _toConsumableArray(column.children));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (outputNodes.length === 0) {
|
|
28
|
+
return nodes;
|
|
29
|
+
}
|
|
30
|
+
return outputNodes;
|
|
31
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
|
|
2
2
|
import { flattenListStep } from './flattenListStep';
|
|
3
3
|
import { flattenStep } from './flattenStep';
|
|
4
|
+
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
4
5
|
import { stubStep } from './stubStep';
|
|
5
6
|
import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
6
7
|
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
@@ -67,6 +68,26 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
67
68
|
blockquote: [unwrapExpandStep, wrapStep],
|
|
68
69
|
paragraph: [unwrapExpandStep],
|
|
69
70
|
codeBlock: [unwrapExpandStep, flattenStep, wrapStep]
|
|
71
|
+
},
|
|
72
|
+
blockquote: {
|
|
73
|
+
expand: [wrapStep],
|
|
74
|
+
nestedExpand: [wrapStep],
|
|
75
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
76
|
+
codeBlock: [unwrapStep, flattenStep, wrapStep]
|
|
77
|
+
},
|
|
78
|
+
layoutSection: {
|
|
79
|
+
blockquote: [unwrapLayoutStep, wrapStep],
|
|
80
|
+
expand: [unwrapLayoutStep, wrapStep],
|
|
81
|
+
panel: [unwrapLayoutStep, wrapStep],
|
|
82
|
+
codeBlock: [unwrapLayoutStep, flattenStep, wrapStep],
|
|
83
|
+
paragraph: [unwrapLayoutStep]
|
|
84
|
+
},
|
|
85
|
+
codeBlock: {
|
|
86
|
+
blockquote: [wrapStep],
|
|
87
|
+
expand: [wrapStep],
|
|
88
|
+
nestedExpand: [wrapStep],
|
|
89
|
+
layoutSection: [wrapIntoLayoutStep],
|
|
90
|
+
panel: [wrapStep]
|
|
70
91
|
}
|
|
71
92
|
};
|
|
72
93
|
var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
|
|
@@ -84,8 +105,8 @@ export var getOutputNodes = function getOutputNodes(_ref) {
|
|
|
84
105
|
isNested = _ref.isNested;
|
|
85
106
|
var nodesToReplace = [sourceNode];
|
|
86
107
|
var selectedNodeTypeName = toNodeTypeValue(sourceNode.type.name);
|
|
87
|
-
var
|
|
88
|
-
targetNodeTypeName = getTargetNodeTypeNameInContext(
|
|
108
|
+
var initialTargetNodeTypeName = toNodeTypeValue(targetNodeType.name);
|
|
109
|
+
var targetNodeTypeName = getTargetNodeTypeNameInContext(initialTargetNodeTypeName, isNested);
|
|
89
110
|
if (!selectedNodeTypeName || !targetNodeTypeName) {
|
|
90
111
|
// We may decide to return an empty array or undefined here
|
|
91
112
|
return;
|
|
@@ -100,7 +121,6 @@ export var getOutputNodes = function getOutputNodes(_ref) {
|
|
|
100
121
|
return;
|
|
101
122
|
}
|
|
102
123
|
return steps.reduce(function (nodes, step) {
|
|
103
|
-
|
|
104
|
-
return result;
|
|
124
|
+
return step(nodes, context);
|
|
105
125
|
}, nodesToReplace);
|
|
106
126
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { unwrapStep } from './unwrapStep';
|
|
3
|
+
|
|
2
4
|
/**
|
|
3
5
|
* Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
|
|
4
6
|
* and prepending it to the children.
|
|
@@ -8,8 +10,11 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
8
10
|
export var unwrapExpandStep = function unwrapExpandStep(nodes, context) {
|
|
9
11
|
var schema = context.schema;
|
|
10
12
|
var outputNodes = [];
|
|
13
|
+
var _schema$nodes = schema.nodes,
|
|
14
|
+
expand = _schema$nodes.expand,
|
|
15
|
+
nestedExpand = _schema$nodes.nestedExpand;
|
|
11
16
|
nodes.forEach(function (node) {
|
|
12
|
-
var isExpand = node.type.name ===
|
|
17
|
+
var isExpand = node.type.name === expand.name || node.type.name === nestedExpand.name;
|
|
13
18
|
if (isExpand) {
|
|
14
19
|
var _node$attrs;
|
|
15
20
|
var title = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title;
|
|
@@ -25,12 +30,7 @@ export var unwrapExpandStep = function unwrapExpandStep(nodes, context) {
|
|
|
25
30
|
// Add the children
|
|
26
31
|
outputNodes.push.apply(outputNodes, _toConsumableArray(node.children));
|
|
27
32
|
} else {
|
|
28
|
-
|
|
29
|
-
if (node.children.length === 0) {
|
|
30
|
-
outputNodes.push(node);
|
|
31
|
-
} else {
|
|
32
|
-
outputNodes.push.apply(outputNodes, _toConsumableArray(node.children));
|
|
33
|
-
}
|
|
33
|
+
unwrapStep([node], context);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
return outputNodes;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
/**
|
|
3
|
-
* Given an array of nodes,
|
|
3
|
+
* Given an array of nodes, processes each list removing all parent list nodes and
|
|
4
|
+
* just returning their child contents.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* Input:
|
|
8
|
+
* - bulletList
|
|
9
|
+
* - listItem "1"
|
|
10
|
+
* - paragraph "1"
|
|
11
|
+
* - listItem "2"
|
|
12
|
+
* - paragraph "2"
|
|
13
|
+
*
|
|
14
|
+
* Output:
|
|
15
|
+
* - paragraph "1"
|
|
16
|
+
* - paragraph "2"
|
|
17
|
+
*
|
|
4
18
|
* @param nodes
|
|
19
|
+
* @param context
|
|
5
20
|
* @returns
|
|
6
21
|
*/
|
|
7
22
|
export var unwrapListStep = function unwrapListStep(nodes, context) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
1
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { findParentNodeOfType, hasParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
3
4
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
4
5
|
export var getSelectedNode = function getSelectedNode(selection) {
|
|
5
6
|
if (selection instanceof NodeSelection) {
|
|
@@ -48,4 +49,32 @@ export var getTargetNodeTypeNameInContext = function getTargetNodeTypeNameInCont
|
|
|
48
49
|
return 'nestedExpand';
|
|
49
50
|
}
|
|
50
51
|
return nodeTypeName;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Use common expandToBlockRange function, but account for edge cases with lists.
|
|
56
|
+
*
|
|
57
|
+
* @param selection
|
|
58
|
+
* @param schema
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export var expandSelectionToBlockRange = function expandSelectionToBlockRange(selection, schema) {
|
|
62
|
+
var isListInSelection = hasParentNode(function (node) {
|
|
63
|
+
return node.type === schema.nodes.bulletList || node.type === schema.nodes.orderedList;
|
|
64
|
+
})(selection);
|
|
65
|
+
var _expandToBlockRange = expandToBlockRange(selection.$from, selection.$to, function (node) {
|
|
66
|
+
if (!isListInSelection) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (node.type === schema.nodes.bulletList || node.type === schema.nodes.orderedList) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}),
|
|
74
|
+
$from = _expandToBlockRange.$from,
|
|
75
|
+
$to = _expandToBlockRange.$to;
|
|
76
|
+
return {
|
|
77
|
+
$from: $from,
|
|
78
|
+
$to: $to
|
|
79
|
+
};
|
|
51
80
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export var wrapStep = function wrapStep(nodes, context) {
|
|
2
2
|
var schema = context.schema,
|
|
3
3
|
targetNodeTypeName = context.targetNodeTypeName;
|
|
4
|
-
// edge case: nestedExpand
|
|
5
4
|
var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, nodes);
|
|
6
5
|
if (outputNode) {
|
|
7
6
|
return [outputNode];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { expandToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import { isNestedNode } from '../ui/utils/isNestedNode';
|
|
4
3
|
import { getOutputNodes } from './transform-node-utils/transform';
|
|
4
|
+
import { expandSelectionToBlockRange } from './transform-node-utils/utils';
|
|
5
5
|
import { isListNode } from './transforms/utils';
|
|
6
6
|
export var transformNode = function transformNode(api) {
|
|
7
7
|
return (
|
|
@@ -14,9 +14,9 @@ export var transformNode = function transformNode(api) {
|
|
|
14
14
|
if (!preservedSelection) {
|
|
15
15
|
return tr;
|
|
16
16
|
}
|
|
17
|
-
var
|
|
18
|
-
$from =
|
|
19
|
-
$to =
|
|
17
|
+
var _expandSelectionToBlo = expandSelectionToBlockRange(preservedSelection, tr.doc.type.schema),
|
|
18
|
+
$from = _expandSelectionToBlo.$from,
|
|
19
|
+
$to = _expandSelectionToBlo.$to;
|
|
20
20
|
var isNested = isNestedNode(preservedSelection, '');
|
|
21
21
|
var selectedParent = $from.parent;
|
|
22
22
|
var fragment = Fragment.empty;
|