@atlaskit/editor-plugin-block-menu 5.2.8 → 5.2.10

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.
Files changed (24) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/editor-actions/index.js +3 -13
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +12 -12
  4. package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +96 -119
  5. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
  6. package/dist/cjs/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -4
  7. package/dist/cjs/editor-commands/transform-node-utils/utils.js +17 -1
  8. package/dist/es2019/editor-actions/index.js +1 -11
  9. package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +10 -12
  10. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +93 -118
  11. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
  12. package/dist/es2019/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -2
  13. package/dist/es2019/editor-commands/transform-node-utils/utils.js +16 -0
  14. package/dist/esm/editor-actions/index.js +2 -13
  15. package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +11 -12
  16. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +95 -119
  17. package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +0 -23
  18. package/dist/esm/editor-commands/transform-node-utils/unwrapExpandStep.js +20 -3
  19. package/dist/esm/editor-commands/transform-node-utils/utils.js +16 -0
  20. package/dist/types/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +5 -0
  21. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +6 -0
  22. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +5 -0
  23. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +6 -0
  24. package/package.json +3 -3
@@ -1,148 +1,122 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
1
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
3
  import { isListType } from '../utils';
3
4
 
4
5
  /**
5
- * Converts FROM taskList structure TO bulletList/orderedList structure.
6
- */
7
- var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
8
- var schema = node.type.schema;
9
- var targetListNodeType = schema.nodes[targetListType];
10
- var convertedItems = [];
11
- node.content.forEach(function (child) {
12
- if (isListType(child, schema)) {
13
- // This is a nested list - it should become a child of the previous item
14
- if (convertedItems.length > 0) {
15
- var previousItem = convertedItems[convertedItems.length - 1];
16
- // Convert the nested list and add it to the previous item's content
17
- var convertedNestedList = _transformList(child, targetListType, targetItemType);
18
- var newContent = previousItem.content.append(Fragment.from([convertedNestedList]));
19
- var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
20
- convertedItems[convertedItems.length - 1] = updatedItem;
21
- }
22
- // If there's no previous item, skip this nested list (orphaned)
23
- } else {
24
- var convertedItem = transformListItem(child, targetItemType, targetListType);
25
- if (convertedItem) {
26
- convertedItems.push(convertedItem);
27
- }
28
- }
29
- });
30
- return targetListNodeType.create(node.attrs, Fragment.from(convertedItems));
31
- };
32
-
33
- /**
34
- * Converts FROM bulletList/orderedList structure TO taskList structure.
6
+ * Recursively converts nested lists to the target list type.
7
+ * This function handles the conversion of both the list container and its items,
8
+ * including any nested lists within those items.
9
+ *
10
+ * Important: taskList has a different nesting structure than bulletList/orderedList:
11
+ * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
12
+ * - bulletList/orderedList: nested lists are CHILDREN of listItems
35
13
  */
36
- var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
14
+ var _transformList = function transformList(node, targetListType, targetItemType, unsupportedContent) {
37
15
  var schema = node.type.schema;
38
- var targetListNodeType = schema.nodes[targetListType];
39
- var transformedContent = [];
40
- node.content.forEach(function (itemNode) {
41
- var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
42
- if (transformedItem) {
43
- transformedContent.push(transformedItem);
44
- }
45
- itemNode.content.forEach(function (child) {
16
+ var taskListType = schema.nodes.taskList;
17
+ var isSourceTaskList = node.type === taskListType;
18
+ var isTargetTaskList = targetListType === 'taskList';
19
+ var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
20
+ var schema = node.type.schema;
21
+ var targetListNodeType = schema.nodes[targetListType];
22
+ var transformedContent = [];
23
+ node.forEach(function (child) {
46
24
  if (isListType(child, schema)) {
47
- var transformedNestedList = _transformList(child, targetListType, targetItemType);
48
- transformedContent.push(transformedNestedList);
25
+ // This is a nested list - it should become a child of the previous item
26
+ if (transformedContent.length > 0) {
27
+ var previousItem = transformedContent[transformedContent.length - 1];
28
+ // Convert the nested list and add it to the previous item's content
29
+ var transformedNestedList = _transformList(child, targetListType, targetItemType, unsupportedContent);
30
+ var newContent = previousItem.content.append(Fragment.from([transformedNestedList]));
31
+ var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
32
+ transformedContent[transformedContent.length - 1] = updatedItem;
33
+ }
34
+ // If there's no previous item, skip this nested list (orphaned)
35
+ } else {
36
+ var transformedItem = transformListItem(child, targetItemType, targetListType);
37
+ if (transformedItem) {
38
+ transformedContent.push(transformedItem);
39
+ }
49
40
  }
50
41
  });
51
- });
52
- return targetListNodeType.create(node.attrs, Fragment.from(transformedContent));
53
- };
54
-
55
- /**
56
- * Converts a single list item (listItem or taskItem) to the target item type.
57
- * Handles content transformation based on the target type's requirements.
58
- * @param itemNode - The list item node to convert
59
- * @param targetItemType - The target item type (listItem or taskItem)
60
- * @param targetListType - The target list type (bulletList, orderedList, or taskList)
61
- * @param excludeNestedLists - When true, nested lists are excluded from the item's content
62
- * (used when converting to taskList where nested lists become siblings)
63
- */
64
- var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
65
- var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
66
- var schema = itemNode.type.schema;
67
- var targetItemNodeType = schema.nodes[targetItemType];
68
- var isTargetTaskItem = targetItemType === 'taskItem';
69
- var isSourceTaskItem = itemNode.type.name === 'taskItem';
70
- var paragraphType = schema.nodes.paragraph;
71
- if (!targetItemNodeType) {
72
- return null;
73
- }
74
- if (isTargetTaskItem) {
75
- var inlineContent = [];
76
- itemNode.content.forEach(function (child) {
77
- if (child.type === paragraphType) {
78
- child.content.forEach(function (inline) {
79
- inlineContent.push(inline);
80
- });
81
- }
82
- if (child.isText) {
83
- inlineContent.push(child);
42
+ return targetListNodeType.create(node.attrs, transformedContent);
43
+ };
44
+ var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
45
+ var schema = node.type.schema;
46
+ var targetListNodeType = schema.nodes[targetListType];
47
+ var transformedContent = [];
48
+ node.forEach(function (itemNode) {
49
+ var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
50
+ if (transformedItem) {
51
+ transformedContent.push(transformedItem);
84
52
  }
85
- // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
86
- // Nested lists will be extracted and placed as siblings in the taskList
53
+ itemNode.forEach(function (child) {
54
+ if (isListType(child, schema)) {
55
+ transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
56
+ }
57
+ });
87
58
  });
88
- return targetItemNodeType.create({}, Fragment.from(inlineContent));
89
- } else {
90
- var newContent = [];
59
+ return targetListNodeType.create(node.attrs, transformedContent);
60
+ };
61
+ var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
62
+ var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
63
+ var schema = itemNode.type.schema;
64
+ var targetItemNodeType = schema.nodes[targetItemType];
65
+ var isTargetTaskItem = targetItemType === 'taskItem';
66
+ var isSourceTaskItem = itemNode.type.name === 'taskItem';
67
+ var paragraphType = schema.nodes.paragraph;
68
+ if (isTargetTaskItem) {
69
+ var inlineContent = [];
70
+ itemNode.forEach(function (child) {
71
+ if (child.type === paragraphType) {
72
+ inlineContent.push.apply(inlineContent, _toConsumableArray(child.children));
73
+ } else if (child.isText) {
74
+ inlineContent.push(child);
75
+ // Nested lists will be extracted and placed as siblings in the taskList
76
+ } else if (!isListType(child, schema)) {
77
+ unsupportedContent.push(child);
78
+ }
79
+ });
80
+ return targetItemNodeType.create({}, inlineContent);
81
+ }
82
+ var transformedContent = [];
91
83
  if (isSourceTaskItem) {
92
- newContent.push(paragraphType.create(null, itemNode.content));
84
+ transformedContent.push(paragraphType.create(null, itemNode.content));
93
85
  } else {
94
- itemNode.content.forEach(function (child) {
86
+ itemNode.forEach(function (child) {
95
87
  if (isListType(child, schema)) {
96
88
  if (excludeNestedLists) {
97
89
  // Skip nested lists - they will be handled separately as siblings
98
90
  return;
99
91
  }
100
- newContent.push(_transformList(child, targetListType, targetItemType));
92
+ transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
101
93
  } else {
102
- newContent.push(child);
94
+ transformedContent.push(child);
103
95
  }
104
96
  });
105
97
  }
106
- if (newContent.length === 0) {
107
- newContent.push(paragraphType.create());
98
+ if (transformedContent.length === 0) {
99
+ transformedContent.push(paragraphType.create());
108
100
  }
109
- return targetItemNodeType.create({}, Fragment.from(newContent));
110
- }
111
- };
112
-
113
- /**
114
- * Recursively converts nested lists to the target list type.
115
- * This function handles the conversion of both the list container and its items,
116
- * including any nested lists within those items.
117
- *
118
- * Important: taskList has a different nesting structure than bulletList/orderedList:
119
- * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
120
- * - bulletList/orderedList: nested lists are CHILDREN of listItems
121
- */
122
- var _transformList = function transformList(node, targetListType, targetItemType) {
123
- var schema = node.type.schema;
124
- var targetListNodeType = schema.nodes[targetListType];
125
- var targetItemNodeType = schema.nodes[targetItemType];
126
- var taskListType = schema.nodes.taskList;
127
- if (!targetListNodeType || !targetItemNodeType) {
128
- return node;
129
- }
130
- var isSourceTaskList = node.type === taskListType;
131
- var isTargetTaskList = targetListType === 'taskList';
101
+ return targetItemNodeType.create({}, transformedContent);
102
+ };
103
+ var convertList = function convertList(node, schema, targetListType, targetItemType) {
104
+ var targetListNodeType = schema.nodes[targetListType];
105
+ var transformedContent = [];
106
+ node.forEach(function (childNode) {
107
+ var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType, unsupportedContent) : transformListItem(childNode, targetItemType, targetListType);
108
+ if (transformedItem) {
109
+ transformedContent.push(transformedItem);
110
+ }
111
+ });
112
+ return targetListNodeType.create(node.attrs, transformedContent);
113
+ };
132
114
  if (isSourceTaskList && !isTargetTaskList) {
133
115
  return convertFromTaskListStructure(node, targetListType, targetItemType);
134
116
  } else if (!isSourceTaskList && isTargetTaskList) {
135
117
  return convertToTaskListStructure(node, targetListType, targetItemType);
136
- } else {
137
- var transformedItems = [];
138
- node.content.forEach(function (childNode) {
139
- var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
140
- if (transformedItem) {
141
- transformedItems.push(transformedItem);
142
- }
143
- });
144
- return targetListNodeType.create(node.attrs, Fragment.from(transformedItems));
145
118
  }
119
+ return convertList(node, schema, targetListType, targetItemType);
146
120
  };
147
121
 
148
122
  /**
@@ -211,11 +185,13 @@ var _transformList = function transformList(node, targetListType, targetItemType
211
185
  export var listToListStep = function listToListStep(nodes, context) {
212
186
  var schema = context.schema,
213
187
  targetNodeTypeName = context.targetNodeTypeName;
214
- return nodes.map(function (node) {
188
+ var unsupportedContent = [];
189
+ var transformedNodes = nodes.map(function (node) {
215
190
  if (isListType(node, schema)) {
216
191
  var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
217
- return _transformList(node, targetNodeTypeName, targetItemType);
192
+ return _transformList(node, targetNodeTypeName, targetItemType, unsupportedContent);
218
193
  }
219
194
  return node;
220
195
  });
196
+ return [].concat(_toConsumableArray(transformedNodes), unsupportedContent);
221
197
  };
@@ -43,21 +43,6 @@ var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeT
43
43
  return targetNodeType.validContent(Fragment.from(node));
44
44
  };
45
45
 
46
- /**
47
- * Converts a nestedExpand to a regular expand node.
48
- * NestedExpands can only exist inside expands, so when breaking out they must be converted.
49
- */
50
- var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
51
- var _node$attrs;
52
- var expandType = schema.nodes.expand;
53
- if (!expandType) {
54
- return null;
55
- }
56
- return expandType.createAndFill({
57
- title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
58
- }, node.content);
59
- };
60
-
61
46
  /**
62
47
  * A wrap step that handles mixed content according to the Compatibility Matrix:
63
48
  * - Wraps consecutive compatible nodes into the target container
@@ -103,14 +88,6 @@ export var wrapMixedContentStep = function wrapMixedContentStep(nodes, context)
103
88
  // This handles: "If there's a panel in the expand, it breaks out into a separate panel"
104
89
  flushCurrentContainer();
105
90
  result.push(node);
106
- } else if (node.type.name === 'nestedExpand') {
107
- // NestedExpand can't be wrapped and can't exist outside an expand
108
- // Convert to regular expand and break out
109
- flushCurrentContainer();
110
- var expandNode = convertNestedExpandToExpand(node, schema);
111
- if (expandNode) {
112
- result.push(expandNode);
113
- }
114
91
  } else if (isTextNode(node)) {
115
92
  // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
116
93
  // Example: heading can't go in blockquote, so convert to paragraph with same content
@@ -1,11 +1,16 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import { unwrapStep } from './unwrapStep';
2
+ import { convertNestedExpandToExpand } from './utils';
3
3
 
4
4
  /**
5
5
  * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
6
6
  * and prepending it to the children.
7
7
  *
8
+ * Any nestedExpand children are converted to regular expands since nestedExpand
9
+ * can only exist inside an expand.
10
+ *
8
11
  * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
12
+ * Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
13
+ * → [p('outer'), expand({ title: 'inner' })(p('x'))]
9
14
  */
10
15
  export var unwrapExpandStep = function unwrapExpandStep(nodes, context) {
11
16
  var schema = context.schema;
@@ -27,8 +32,20 @@ export var unwrapExpandStep = function unwrapExpandStep(nodes, context) {
27
32
  }
28
33
  }
29
34
 
30
- // Add the children
31
- outputNodes.push.apply(outputNodes, _toConsumableArray(node.children));
35
+ // Add the children, converting any nestedExpands to regular expands
36
+ // since nestedExpand can only exist inside an expand
37
+ node.children.forEach(function (child) {
38
+ if (child.type.name === nestedExpand.name) {
39
+ var expandNode = convertNestedExpandToExpand(child, schema);
40
+ if (expandNode) {
41
+ outputNodes.push(expandNode);
42
+ } else {
43
+ outputNodes.push(child);
44
+ }
45
+ } else {
46
+ outputNodes.push(child);
47
+ }
48
+ });
32
49
  } else {
33
50
  unwrapStep([node], context);
34
51
  }
@@ -106,6 +106,22 @@ export var isListType = function isListType(node, schema) {
106
106
  return list === node.type;
107
107
  });
108
108
  };
109
+
110
+ /**
111
+ * Converts a nestedExpand to a regular expand node.
112
+ * NestedExpands can only exist inside expands, so when breaking out or placing
113
+ * in containers that don't support nesting, they must be converted.
114
+ */
115
+ export var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
116
+ var _node$attrs;
117
+ var expandType = schema.nodes.expand;
118
+ if (!expandType) {
119
+ return null;
120
+ }
121
+ return expandType.createAndFill({
122
+ title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
123
+ }, node.content);
124
+ };
109
125
  export var getBlockNodesInRange = function getBlockNodesInRange(range) {
110
126
  if (range.endIndex - range.startIndex <= 1) {
111
127
  return [range.parent.child(range.startIndex)];
@@ -3,6 +3,11 @@ import type { TransformStep } from './types';
3
3
  * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
4
4
  * and prepending it to the children.
5
5
  *
6
+ * Any nestedExpand children are converted to regular expands since nestedExpand
7
+ * can only exist inside an expand.
8
+ *
6
9
  * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
10
+ * Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
11
+ * → [p('outer'), expand({ title: 'inner' })(p('x'))]
7
12
  */
8
13
  export declare const unwrapExpandStep: TransformStep;
@@ -16,4 +16,10 @@ export declare const expandSelectionToBlockRange: (selection: Selection, schema:
16
16
  $to: import("prosemirror-model").ResolvedPos;
17
17
  };
18
18
  export declare const isListType: (node: PMNode, schema: Schema) => boolean;
19
+ /**
20
+ * Converts a nestedExpand to a regular expand node.
21
+ * NestedExpands can only exist inside expands, so when breaking out or placing
22
+ * in containers that don't support nesting, they must be converted.
23
+ */
24
+ export declare const convertNestedExpandToExpand: (node: PMNode, schema: Schema) => PMNode | null;
19
25
  export declare const getBlockNodesInRange: (range: NodeRange) => PMNode[];
@@ -3,6 +3,11 @@ import type { TransformStep } from './types';
3
3
  * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
4
4
  * and prepending it to the children.
5
5
  *
6
+ * Any nestedExpand children are converted to regular expands since nestedExpand
7
+ * can only exist inside an expand.
8
+ *
6
9
  * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
10
+ * Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
11
+ * → [p('outer'), expand({ title: 'inner' })(p('x'))]
7
12
  */
8
13
  export declare const unwrapExpandStep: TransformStep;
@@ -16,4 +16,10 @@ export declare const expandSelectionToBlockRange: (selection: Selection, schema:
16
16
  $to: import("prosemirror-model").ResolvedPos;
17
17
  };
18
18
  export declare const isListType: (node: PMNode, schema: Schema) => boolean;
19
+ /**
20
+ * Converts a nestedExpand to a regular expand node.
21
+ * NestedExpands can only exist inside expands, so when breaking out or placing
22
+ * in containers that don't support nesting, they must be converted.
23
+ */
24
+ export declare const convertNestedExpandToExpand: (node: PMNode, schema: Schema) => PMNode | null;
19
25
  export declare const getBlockNodesInRange: (range: NodeRange) => PMNode[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.2.8",
3
+ "version": "5.2.10",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -45,11 +45,11 @@
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^16.4.0",
47
47
  "@atlaskit/tmp-editor-statsig": "^15.10.0",
48
- "@atlaskit/tokens": "^8.4.0",
48
+ "@atlaskit/tokens": "^8.5.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^110.42.0",
52
+ "@atlaskit/editor-common": "^110.43.0",
53
53
  "react": "^18.2.0",
54
54
  "react-intl-next": "npm:react-intl@^5.18.1"
55
55
  },