@atlaskit/editor-plugin-block-menu 5.2.7 → 5.2.9

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 (25) 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/transform.js +8 -2
  6. package/dist/cjs/editor-commands/transform-node-utils/utils.js +17 -1
  7. package/dist/cjs/editor-commands/transform-node-utils/wrapIntoListStep.js +17 -0
  8. package/dist/cjs/editor-commands/transformNode.js +13 -4
  9. package/dist/es2019/editor-actions/index.js +1 -11
  10. package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +10 -12
  11. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +93 -118
  12. package/dist/es2019/editor-commands/transform-node-utils/transform.js +8 -2
  13. package/dist/es2019/editor-commands/transform-node-utils/utils.js +17 -1
  14. package/dist/es2019/editor-commands/transform-node-utils/wrapIntoListStep.js +13 -0
  15. package/dist/es2019/editor-commands/transformNode.js +15 -4
  16. package/dist/esm/editor-actions/index.js +2 -13
  17. package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +11 -12
  18. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +95 -119
  19. package/dist/esm/editor-commands/transform-node-utils/transform.js +8 -2
  20. package/dist/esm/editor-commands/transform-node-utils/utils.js +17 -1
  21. package/dist/esm/editor-commands/transform-node-utils/wrapIntoListStep.js +11 -0
  22. package/dist/esm/editor-commands/transformNode.js +13 -4
  23. package/dist/types/editor-commands/transform-node-utils/wrapIntoListStep.d.ts +3 -0
  24. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapIntoListStep.d.ts +3 -0
  25. package/package.json +5 -5
@@ -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
  };
@@ -13,6 +13,7 @@ import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
13
13
  import { unwrapExpandStep } from './unwrapExpandStep';
14
14
  import { unwrapStep } from './unwrapStep';
15
15
  import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
16
+ import { wrapIntoListStep } from './wrapIntoListStep';
16
17
  import { wrapStep } from './wrapStep';
17
18
 
18
19
  // Exampled step for overrides:
@@ -28,7 +29,7 @@ var TRANSFORM_STEPS = {
28
29
  atomic: {
29
30
  atomic: undefined,
30
31
  container: [wrapStep],
31
- list: undefined,
32
+ list: [wrapIntoListStep],
32
33
  text: undefined
33
34
  },
34
35
  container: {
@@ -116,7 +117,12 @@ var TRANSFORM_STEPS_OVERRIDE = {
116
117
  decisionList: [flattenListStep, listToDecisionListStep]
117
118
  },
118
119
  table: {
119
- expand: [wrapStep],
120
+ layoutSection: [wrapIntoLayoutStep]
121
+ },
122
+ mediaSingle: {
123
+ layoutSection: [wrapIntoLayoutStep]
124
+ },
125
+ mediaGroup: {
120
126
  layoutSection: [wrapIntoLayoutStep]
121
127
  },
122
128
  decisionList: {
@@ -70,13 +70,29 @@ export var expandSelectionToBlockRange = function expandSelectionToBlockRange(se
70
70
  var table = findTable(selection);
71
71
  if (table) {
72
72
  var $from = selection.$from.doc.resolve(table.pos);
73
- var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize - 1);
73
+ var $to = selection.$from.doc.resolve(table.pos + table.node.nodeSize);
74
74
  return {
75
75
  $from: $from,
76
76
  $to: $to
77
77
  };
78
78
  }
79
79
  }
80
+
81
+ // when selecting a file, selection is on media
82
+ // need to find media group and return its pos
83
+ if (selection instanceof NodeSelection) {
84
+ if (selection.node.type === nodes.media) {
85
+ var mediaGroup = findParentNodeOfType(nodes.mediaGroup)(selection);
86
+ if (mediaGroup) {
87
+ var _$from = selection.$from.doc.resolve(mediaGroup.pos);
88
+ var _$to = selection.$from.doc.resolve(mediaGroup.pos + mediaGroup.node.nodeSize);
89
+ return {
90
+ $from: _$from,
91
+ $to: _$to
92
+ };
93
+ }
94
+ }
95
+ }
80
96
  return expandToBlockRange(selection.$from, selection.$to, function (node) {
81
97
  if (nodesNeedToExpandRange.includes(node.type)) {
82
98
  return false;
@@ -0,0 +1,11 @@
1
+ /** wrap nodes into bullet list or numbered list, does not work for task list */
2
+ export var wrapIntoListStep = function wrapIntoListStep(nodes, context) {
3
+ var schema = context.schema,
4
+ targetNodeTypeName = context.targetNodeTypeName;
5
+ var listItemNode = schema.nodes.listItem.createAndFill({}, nodes);
6
+ var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, listItemNode);
7
+ if (outputNode) {
8
+ return [outputNode];
9
+ }
10
+ return nodes;
11
+ };
@@ -1,4 +1,5 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { isNestedNode } from '../ui/utils/isNestedNode';
3
4
  import { getOutputNodes } from './transform-node-utils/transform';
4
5
  import { expandSelectionToBlockRange } from './transform-node-utils/utils';
@@ -14,7 +15,9 @@ export var transformNode = function transformNode(api) {
14
15
  if (!preservedSelection) {
15
16
  return tr;
16
17
  }
17
- var _expandSelectionToBlo = expandSelectionToBlockRange(preservedSelection, tr.doc.type.schema),
18
+ var schema = tr.doc.type.schema;
19
+ var nodes = schema.nodes;
20
+ var _expandSelectionToBlo = expandSelectionToBlockRange(preservedSelection, schema),
18
21
  $from = _expandSelectionToBlo.$from,
19
22
  $to = _expandSelectionToBlo.$to;
20
23
  var isNested = isNestedNode(preservedSelection, '');
@@ -33,9 +36,15 @@ export var transformNode = function transformNode(api) {
33
36
  fragment = fragment.append(Fragment.fromArray(outputNode));
34
37
  }
35
38
  });
36
-
37
- // TODO: ED-12345 - selection is broken post transaction, to fix.
38
- tr.replaceWith(isList ? $from.pos - 1 : $from.pos, $to.pos, fragment);
39
+ var nodesToDeleteAndInsert = [nodes.mediaSingle];
40
+ if (preservedSelection instanceof NodeSelection && nodesToDeleteAndInsert.includes(preservedSelection.node.type)) {
41
+ // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
42
+ tr.deleteRange($from.pos, $to.pos);
43
+ tr.insert($from.pos, fragment);
44
+ } else {
45
+ // TODO: ED-12345 - selection is broken post transaction, to fix.
46
+ tr.replaceWith(isList ? $from.pos - 1 : $from.pos, $to.pos, fragment);
47
+ }
39
48
  return tr;
40
49
  };
41
50
  }
@@ -0,0 +1,3 @@
1
+ import type { TransformStep } from './types';
2
+ /** wrap nodes into bullet list or numbered list, does not work for task list */
3
+ export declare const wrapIntoListStep: TransformStep;
@@ -0,0 +1,3 @@
1
+ import type { TransformStep } from './types';
2
+ /** wrap nodes into bullet list or numbered list, does not work for task list */
3
+ export declare const wrapIntoListStep: TransformStep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.2.7",
3
+ "version": "5.2.9",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/css": "^0.17.0",
32
32
  "@atlaskit/dropdown-menu": "^16.3.0",
33
33
  "@atlaskit/editor-plugin-analytics": "^6.2.0",
34
- "@atlaskit/editor-plugin-block-controls": "^7.13.0",
34
+ "@atlaskit/editor-plugin-block-controls": "^7.14.0",
35
35
  "@atlaskit/editor-plugin-decorations": "^6.1.0",
36
36
  "@atlaskit/editor-plugin-selection": "^6.1.0",
37
37
  "@atlaskit/editor-plugin-user-intent": "^4.0.0",
@@ -40,16 +40,16 @@
40
40
  "@atlaskit/editor-tables": "^2.9.0",
41
41
  "@atlaskit/editor-toolbar": "^0.18.0",
42
42
  "@atlaskit/flag": "^17.6.0",
43
- "@atlaskit/icon": "^29.0.0",
43
+ "@atlaskit/icon": "^29.1.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^16.4.0",
47
- "@atlaskit/tmp-editor-statsig": "^15.9.0",
47
+ "@atlaskit/tmp-editor-statsig": "^15.10.0",
48
48
  "@atlaskit/tokens": "^8.4.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^110.41.0",
52
+ "@atlaskit/editor-common": "^110.42.0",
53
53
  "react": "^18.2.0",
54
54
  "react-intl-next": "npm:react-intl@^5.18.1"
55
55
  },