@atlaskit/editor-plugin-block-menu 5.1.3 → 5.1.5

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 (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/flattenListStep.js +108 -0
  3. package/dist/cjs/editor-commands/transform-node-utils/flattenStep.js +21 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/transform.js +33 -5
  5. package/dist/cjs/editor-commands/transform-node-utils/types.js +1 -1
  6. package/dist/cjs/editor-commands/transform-node-utils/unwrapExpandStep.js +44 -0
  7. package/dist/cjs/editor-commands/transform-node-utils/unwrapListStep.js +28 -0
  8. package/dist/cjs/editor-commands/transform-node-utils/unwrapStep.js +20 -0
  9. package/dist/cjs/editor-commands/transform-node-utils/utils.js +7 -1
  10. package/dist/cjs/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +23 -0
  11. package/dist/cjs/editor-commands/transform-node-utils/wrapStep.js +16 -0
  12. package/dist/cjs/editor-commands/transformNode.js +12 -6
  13. package/dist/cjs/ui/block-menu.js +20 -7
  14. package/dist/es2019/editor-commands/transform-node-utils/flattenListStep.js +94 -0
  15. package/dist/es2019/editor-commands/transform-node-utils/flattenStep.js +15 -0
  16. package/dist/es2019/editor-commands/transform-node-utils/transform.js +34 -6
  17. package/dist/es2019/editor-commands/transform-node-utils/types.js +1 -1
  18. package/dist/es2019/editor-commands/transform-node-utils/unwrapExpandStep.js +38 -0
  19. package/dist/es2019/editor-commands/transform-node-utils/unwrapListStep.js +18 -0
  20. package/dist/es2019/editor-commands/transform-node-utils/unwrapStep.js +12 -0
  21. package/dist/es2019/editor-commands/transform-node-utils/utils.js +6 -0
  22. package/dist/es2019/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +20 -0
  23. package/dist/es2019/editor-commands/transform-node-utils/wrapStep.js +12 -0
  24. package/dist/es2019/editor-commands/transformNode.js +12 -7
  25. package/dist/es2019/ui/block-menu.js +15 -7
  26. package/dist/esm/editor-commands/transform-node-utils/flattenListStep.js +102 -0
  27. package/dist/esm/editor-commands/transform-node-utils/flattenStep.js +15 -0
  28. package/dist/esm/editor-commands/transform-node-utils/transform.js +33 -5
  29. package/dist/esm/editor-commands/transform-node-utils/types.js +1 -1
  30. package/dist/esm/editor-commands/transform-node-utils/unwrapExpandStep.js +37 -0
  31. package/dist/esm/editor-commands/transform-node-utils/unwrapListStep.js +21 -0
  32. package/dist/esm/editor-commands/transform-node-utils/unwrapStep.js +13 -0
  33. package/dist/esm/editor-commands/transform-node-utils/utils.js +6 -0
  34. package/dist/esm/editor-commands/transform-node-utils/wrapIntoLayoutStep.js +17 -0
  35. package/dist/esm/editor-commands/transform-node-utils/wrapStep.js +10 -0
  36. package/dist/esm/editor-commands/transformNode.js +12 -6
  37. package/dist/esm/ui/block-menu.js +19 -7
  38. package/dist/types/editor-commands/transform-node-utils/flattenListStep.d.ts +49 -0
  39. package/dist/types/editor-commands/transform-node-utils/flattenStep.d.ts +2 -0
  40. package/dist/types/editor-commands/transform-node-utils/transform.d.ts +3 -2
  41. package/dist/types/editor-commands/transform-node-utils/types.d.ts +1 -1
  42. package/dist/types/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +8 -0
  43. package/dist/types/editor-commands/transform-node-utils/unwrapListStep.d.ts +7 -0
  44. package/dist/types/editor-commands/transform-node-utils/unwrapStep.d.ts +2 -0
  45. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +2 -0
  46. package/dist/types/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +2 -0
  47. package/dist/types/editor-commands/transform-node-utils/wrapStep.d.ts +2 -0
  48. package/dist/types/editor-commands/transforms/types.d.ts +1 -1
  49. package/dist/types-ts4.5/editor-commands/transform-node-utils/flattenListStep.d.ts +49 -0
  50. package/dist/types-ts4.5/editor-commands/transform-node-utils/flattenStep.d.ts +2 -0
  51. package/dist/types-ts4.5/editor-commands/transform-node-utils/transform.d.ts +3 -2
  52. package/dist/types-ts4.5/editor-commands/transform-node-utils/types.d.ts +1 -1
  53. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapExpandStep.d.ts +8 -0
  54. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapListStep.d.ts +7 -0
  55. package/dist/types-ts4.5/editor-commands/transform-node-utils/unwrapStep.d.ts +2 -0
  56. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +2 -0
  57. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapIntoLayoutStep.d.ts +2 -0
  58. package/dist/types-ts4.5/editor-commands/transform-node-utils/wrapStep.d.ts +2 -0
  59. package/dist/types-ts4.5/editor-commands/transforms/types.d.ts +1 -1
  60. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f6905b2543ef1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f6905b2543ef1) -
8
+ [ux] Implements base steps for from container to other node categories transfroms.
9
+ - Updated dependencies
10
+
11
+ ## 5.1.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [`7e5df3d5beaf3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e5df3d5beaf3) -
16
+ Add new flattenListStep and unwrapListStep and use for list -> paragraph step. Also moved
17
+ expandToBlockRange util function to editor-common to re-use
18
+ - Updated dependencies
19
+
3
20
  ## 5.1.3
4
21
 
5
22
  ### Patch Changes
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.flattenListStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes) {
9
+ var items = [];
10
+ var _extract = function extract(currentNode) {
11
+ currentNode.forEach(function (child) {
12
+ // list item -> take content without nested lists, then recurse into nested lists
13
+ if (itemTypes.some(function (type) {
14
+ return child.type === type;
15
+ })) {
16
+ // Filter out nested list nodes from the list item's content
17
+ var contentWithoutNestedLists = [];
18
+ var nestedLists = [];
19
+ child.forEach(function (grandChild) {
20
+ if (listTypes.some(function (type) {
21
+ return grandChild.type === type;
22
+ })) {
23
+ // This is a nested list - collect it for later processing
24
+ nestedLists.push(grandChild);
25
+ } else {
26
+ // This is regular content (paragraph, etc.) - keep it
27
+ contentWithoutNestedLists.push(grandChild);
28
+ }
29
+ });
30
+
31
+ // Add the list item with only its non-list content
32
+ items.push(child.copy(_model.Fragment.from(contentWithoutNestedLists)));
33
+
34
+ // Now process nested lists to maintain document order
35
+ nestedLists.forEach(function (nestedList) {
36
+ _extract(nestedList);
37
+ });
38
+ }
39
+ // lists -> keep operating
40
+ else if (listTypes.some(function (type) {
41
+ return child.type === type;
42
+ })) {
43
+ _extract(child);
44
+ }
45
+ });
46
+ };
47
+ _extract(node);
48
+ return items;
49
+ };
50
+
51
+ /**
52
+ * Given an array of nodes, returns an array with the flattened children of any list node
53
+ * to it's first ancestor list, maintaining document order.
54
+ *
55
+ * @example
56
+ * Input:
57
+ * - bulletList
58
+ * - listItem "A"
59
+ * - listItem "B"
60
+ * - bulletList
61
+ * - listItem "C"
62
+ * - listItem "D"
63
+ * - listItem "E"
64
+ *
65
+ * Output:
66
+ * - bulletList
67
+ * - listItem "A"
68
+ * - listItem "B"
69
+ * - listItem "C"
70
+ * - listItem "D"
71
+ * - listItem "E"
72
+ *
73
+ * @example
74
+ * Input (deeply nested):
75
+ * - bulletList
76
+ * - listItem "1"
77
+ * - bulletList
78
+ * - listItem "1.1"
79
+ * - bulletList
80
+ * - listItem "1.1.1"
81
+ * - listItem "1.2"
82
+ * - listItem "2"
83
+ *
84
+ * Output:
85
+ * - bulletList
86
+ * - listItem "1"
87
+ * - listItem "1.1"
88
+ * - listItem "1.1.1"
89
+ * - listItem "1.2"
90
+ * - listItem "2"
91
+ *
92
+ * @param nodes
93
+ * @param context
94
+ * @returns
95
+ *
96
+ * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
97
+ */
98
+ var flattenListStep = exports.flattenListStep = function flattenListStep(nodes, context) {
99
+ var listTypes = [context.schema.nodes.bulletList, context.schema.nodes.orderedList, context.schema.nodes.taskList];
100
+ return nodes.map(function (node) {
101
+ if (listTypes.some(function (type) {
102
+ return node.type === type;
103
+ })) {
104
+ return node.copy(_model.Fragment.from(extractNestedLists(node, listTypes, [context.schema.nodes.listItem, context.schema.nodes.taskItem])));
105
+ }
106
+ return node;
107
+ });
108
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.flattenStep = void 0;
7
+ var flattenStep = exports.flattenStep = function flattenStep(nodes, context) {
8
+ var schema = context.schema,
9
+ targetNodeTypeName = context.targetNodeTypeName;
10
+
11
+ // TODO: EDITOR-2920 - Implement flattening logic.
12
+ // This is a simplified preliminary approach. We might want to use prosemirror-markdown functions.
13
+ var codeBlockContent = nodes.map(function (node) {
14
+ return node.content.textBetween(0, node.content.size, '\n');
15
+ }).join('\n');
16
+ var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, schema.text(codeBlockContent));
17
+ if (!outputNode) {
18
+ return nodes;
19
+ }
20
+ return [outputNode];
21
+ };
@@ -4,8 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getOutputNodes = void 0;
7
+ var _utils = require("../transform-node-utils/utils");
8
+ var _flattenListStep = require("./flattenListStep");
9
+ var _flattenStep = require("./flattenStep");
7
10
  var _stubStep = require("./stubStep");
8
11
  var _types = require("./types");
12
+ var _unwrapExpandStep = require("./unwrapExpandStep");
13
+ var _unwrapListStep = require("./unwrapListStep");
14
+ var _unwrapStep = require("./unwrapStep");
15
+ var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
16
+ var _wrapStep = require("./wrapStep");
9
17
  // Exampled step for overrides:
10
18
  // - open Block menu on a paragraph, click 'Panel' in the Turn into'
11
19
  // - expected to put paragraph into a panel
@@ -24,15 +32,15 @@ var TRANSFORM_STEPS = {
24
32
  },
25
33
  container: {
26
34
  atomic: undefined,
27
- container: [_stubStep.stubStep],
35
+ container: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
28
36
  list: undefined,
29
- text: undefined
37
+ text: [_unwrapStep.unwrapStep]
30
38
  },
31
39
  list: {
32
40
  atomic: undefined,
33
41
  container: [_stubStep.stubStep],
34
42
  list: [_stubStep.stubStep],
35
- text: [_stubStep.stubStep]
43
+ text: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep]
36
44
  },
37
45
  text: {
38
46
  atomic: undefined,
@@ -47,6 +55,23 @@ var TRANSFORM_STEPS = {
47
55
  var TRANSFORM_STEPS_OVERRIDE = {
48
56
  paragraph: {
49
57
  panel: [wrapIntoPanelStep]
58
+ },
59
+ panel: {
60
+ layoutSection: [_unwrapStep.unwrapStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
61
+ codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
62
+ },
63
+ expand: {
64
+ panel: [_unwrapExpandStep.unwrapExpandStep, _wrapStep.wrapStep],
65
+ blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapStep.wrapStep],
66
+ layoutSection: [_unwrapExpandStep.unwrapExpandStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
67
+ paragraph: [_unwrapExpandStep.unwrapExpandStep],
68
+ codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
69
+ },
70
+ nestedExpand: {
71
+ panel: [_unwrapExpandStep.unwrapExpandStep, _wrapStep.wrapStep],
72
+ blockquote: [_unwrapExpandStep.unwrapExpandStep, _wrapStep.wrapStep],
73
+ paragraph: [_unwrapExpandStep.unwrapExpandStep],
74
+ codeBlock: [_unwrapExpandStep.unwrapExpandStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
50
75
  }
51
76
  };
52
77
  var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
@@ -60,10 +85,12 @@ var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selec
60
85
  var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
61
86
  var sourceNode = _ref.sourceNode,
62
87
  targetNodeType = _ref.targetNodeType,
63
- schema = _ref.schema;
88
+ schema = _ref.schema,
89
+ isNested = _ref.isNested;
64
90
  var nodesToReplace = [sourceNode];
65
91
  var selectedNodeTypeName = (0, _types.toNodeTypeValue)(sourceNode.type.name);
66
92
  var targetNodeTypeName = (0, _types.toNodeTypeValue)(targetNodeType.name);
93
+ targetNodeTypeName = (0, _utils.getTargetNodeTypeNameInContext)(targetNodeTypeName, isNested);
67
94
  if (!selectedNodeTypeName || !targetNodeTypeName) {
68
95
  // We may decide to return an empty array or undefined here
69
96
  return;
@@ -78,6 +105,7 @@ var getOutputNodes = exports.getOutputNodes = function getOutputNodes(_ref) {
78
105
  return;
79
106
  }
80
107
  return steps.reduce(function (nodes, step) {
81
- return step(nodes, context);
108
+ var result = step(nodes, context);
109
+ return result;
82
110
  }, nodesToReplace);
83
111
  };
@@ -15,7 +15,7 @@ var NODE_CATEGORY_BY_TYPE = exports.NODE_CATEGORY_BY_TYPE = {
15
15
  expand: 'container',
16
16
  extension: 'atomic',
17
17
  heading: 'text',
18
- layout: 'container',
18
+ layoutSection: 'container',
19
19
  media: 'atomic',
20
20
  mediaGroup: 'atomic',
21
21
  mediaSingle: 'atomic',
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.unwrapExpandStep = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ /**
10
+ * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
11
+ * and prepending it to the children.
12
+ *
13
+ * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
14
+ */
15
+ var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(nodes, context) {
16
+ var schema = context.schema;
17
+ var outputNodes = [];
18
+ nodes.forEach(function (node) {
19
+ var isExpand = node.type.name === 'expand' || node.type.name === 'nestedExpand';
20
+ if (isExpand) {
21
+ var _node$attrs;
22
+ var title = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title;
23
+
24
+ // Create a paragraph from the title if it exists
25
+ if (title) {
26
+ var titleParagraph = schema.nodes.paragraph.createAndFill({}, schema.text(title));
27
+ if (titleParagraph) {
28
+ outputNodes.push(titleParagraph);
29
+ }
30
+ }
31
+
32
+ // Add the children
33
+ outputNodes.push.apply(outputNodes, (0, _toConsumableArray2.default)(node.children));
34
+ } else {
35
+ // Fallback: behave like unwrapStep for non-expand nodes
36
+ if (node.children.length === 0) {
37
+ outputNodes.push(node);
38
+ } else {
39
+ outputNodes.push.apply(outputNodes, (0, _toConsumableArray2.default)(node.children));
40
+ }
41
+ }
42
+ });
43
+ return outputNodes;
44
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.unwrapListStep = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ /**
10
+ * Given an array of nodes, returns an array with the flattened children of any list nodes.
11
+ * @param nodes
12
+ * @returns
13
+ */
14
+ var unwrapListStep = exports.unwrapListStep = function unwrapListStep(nodes, context) {
15
+ var listTypes = [context.schema.nodes.bulletList, context.schema.nodes.orderedList, context.schema.nodes.taskList];
16
+ return nodes.flatMap(function (node) {
17
+ if (listTypes.some(function (type) {
18
+ return node.type === type;
19
+ })) {
20
+ var listItems = [];
21
+ node.forEach(function (listItem) {
22
+ listItems.push.apply(listItems, (0, _toConsumableArray2.default)(listItem.children));
23
+ });
24
+ return listItems;
25
+ }
26
+ return node;
27
+ });
28
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.unwrapStep = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var unwrapStep = exports.unwrapStep = function unwrapStep(nodes) {
10
+ var outputNodes = [];
11
+ nodes.forEach(function (node) {
12
+ // we may want to just skip the original instead of using it
13
+ if (node.children.length === 0) {
14
+ outputNodes.push(node);
15
+ } else {
16
+ outputNodes.push.apply(outputNodes, (0, _toConsumableArray2.default)(node.children));
17
+ }
18
+ });
19
+ return outputNodes;
20
+ };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSelectedNode = void 0;
6
+ exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = void 0;
7
7
  var _state = require("@atlaskit/editor-prosemirror/state");
8
8
  var _utils = require("@atlaskit/editor-prosemirror/utils");
9
9
  var _editorTables = require("@atlaskit/editor-tables");
@@ -48,4 +48,10 @@ var getSelectedNode = exports.getSelectedNode = function getSelectedNode(selecti
48
48
  }
49
49
  }
50
50
  return undefined;
51
+ };
52
+ var getTargetNodeTypeNameInContext = exports.getTargetNodeTypeNameInContext = function getTargetNodeTypeNameInContext(nodeTypeName, isNested) {
53
+ if (nodeTypeName === 'expand' && isNested) {
54
+ return 'nestedExpand';
55
+ }
56
+ return nodeTypeName;
51
57
  };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapIntoLayoutStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var wrapIntoLayoutStep = exports.wrapIntoLayoutStep = function wrapIntoLayoutStep(nodes, context) {
9
+ var schema = context.schema;
10
+ var _ref = schema.nodes || {},
11
+ layoutSection = _ref.layoutSection,
12
+ layoutColumn = _ref.layoutColumn;
13
+ var columnOne = layoutColumn.createAndFill({}, _model.Fragment.fromArray(nodes));
14
+ var columnTwo = layoutColumn.createAndFill();
15
+ if (!columnOne || !columnTwo) {
16
+ return nodes;
17
+ }
18
+ var layout = layoutSection.createAndFill({}, _model.Fragment.fromArray([columnOne, columnTwo]));
19
+ if (!layout) {
20
+ return nodes;
21
+ }
22
+ return [layout];
23
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapStep = void 0;
7
+ var wrapStep = exports.wrapStep = function wrapStep(nodes, context) {
8
+ var schema = context.schema,
9
+ targetNodeTypeName = context.targetNodeTypeName;
10
+ // edge case: nestedExpand
11
+ var outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, nodes);
12
+ if (outputNode) {
13
+ return [outputNode];
14
+ }
15
+ return nodes;
16
+ };
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.transformNode = void 0;
7
+ var _selection = require("@atlaskit/editor-common/selection");
7
8
  var _model = require("@atlaskit/editor-prosemirror/model");
9
+ var _isNestedNode = require("../ui/utils/isNestedNode");
8
10
  var _transform = require("./transform-node-utils/transform");
9
11
  var _utils = require("./transforms/utils");
10
12
  var transformNode = exports.transformNode = function transformNode(api) {
@@ -18,24 +20,28 @@ var transformNode = exports.transformNode = function transformNode(api) {
18
20
  if (!preservedSelection) {
19
21
  return tr;
20
22
  }
21
- var from = preservedSelection.from,
22
- to = preservedSelection.to,
23
- $from = preservedSelection.$from;
23
+ var _expandToBlockRange = (0, _selection.expandToBlockRange)(preservedSelection.$from, preservedSelection.$to),
24
+ $from = _expandToBlockRange.$from,
25
+ $to = _expandToBlockRange.$to;
26
+ var isNested = (0, _isNestedNode.isNestedNode)(preservedSelection, '');
24
27
  var selectedParent = $from.parent;
25
28
  var fragment = _model.Fragment.empty;
26
29
  var isList = (0, _utils.isListNode)(selectedParent);
27
- var slice = tr.doc.slice(isList ? from - 1 : from, isList ? to + 1 : to);
30
+ var slice = tr.doc.slice(isList ? $from.pos - 1 : $from.pos, isList ? $to.pos + 1 : $to.pos);
28
31
  slice.content.forEach(function (node) {
29
32
  var outputNode = (0, _transform.getOutputNodes)({
30
33
  sourceNode: node,
31
34
  targetNodeType: targetType,
32
- schema: tr.doc.type.schema
35
+ schema: tr.doc.type.schema,
36
+ isNested: isNested
33
37
  });
34
38
  if (outputNode) {
35
39
  fragment = fragment.append(_model.Fragment.fromArray(outputNode));
36
40
  }
37
41
  });
38
- tr.replaceWith(isList ? preservedSelection.from - 1 : preservedSelection.from, preservedSelection.to, fragment);
42
+
43
+ // TODO: ED-12345 - selection is broken post transaction, to fix.
44
+ tr.replaceWith(isList ? $from.pos - 1 : $from.pos, $to.pos, fragment);
39
45
  return tr;
40
46
  };
41
47
  }
@@ -1,6 +1,7 @@
1
1
  /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  "use strict";
3
3
 
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5
  var _typeof = require("@babel/runtime/helpers/typeof");
5
6
  Object.defineProperty(exports, "__esModule", {
6
7
  value: true
@@ -8,6 +9,7 @@ Object.defineProperty(exports, "__esModule", {
8
9
  exports.default = void 0;
9
10
  require("./block-menu.compiled.css");
10
11
  var _runtime = require("@compiled/react/runtime");
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
13
  var _react = _interopRequireWildcard(require("react"));
12
14
  var _reactIntlNext = require("react-intl-next");
13
15
  var _css = require("@atlaskit/css");
@@ -33,6 +35,7 @@ var styles = {
33
35
  };
34
36
  var DEFAULT_MENU_WIDTH = 230;
35
37
  var DRAG_HANDLE_OFFSET_PADDING = 5;
38
+ var FALLBACK_MENU_HEIGHT = 300;
36
39
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
37
40
  var useConditionalBlockMenuEffect = (0, _platformFeatureFlagsReact.conditionalHooksFactory)(function () {
38
41
  return (0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_user_intent_fix');
@@ -163,6 +166,18 @@ var BlockMenu = function BlockMenu(_ref4) {
163
166
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(_styles.DRAG_HANDLE_SELECTOR);
164
167
  var prevIsMenuOpenRef = (0, _react.useRef)(false);
165
168
  var popupRef = (0, _react.useRef)(undefined);
169
+ var _React$useState = _react.default.useState(0),
170
+ _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
171
+ menuHeight = _React$useState2[0],
172
+ setMenuHeight = _React$useState2[1];
173
+ var targetHandleHeightOffset = -((targetHandleRef === null || targetHandleRef === void 0 ? void 0 : targetHandleRef.clientHeight) || 0);
174
+ _react.default.useLayoutEffect(function () {
175
+ var _popupRef$current;
176
+ if (!isMenuOpen) {
177
+ return;
178
+ }
179
+ setMenuHeight(((_popupRef$current = popupRef.current) === null || _popupRef$current === void 0 ? void 0 : _popupRef$current.clientHeight) || FALLBACK_MENU_HEIGHT);
180
+ }, [isMenuOpen]);
166
181
  var hasFocus = (_ref5 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef || popupRef.current && (popupRef.current.contains(document.activeElement) || popupRef.current === document.activeElement)) !== null && _ref5 !== void 0 ? _ref5 : false;
167
182
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
168
183
 
@@ -226,8 +241,7 @@ var BlockMenu = function BlockMenu(_ref4) {
226
241
  fallbackComponent: null
227
242
  }, /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
228
243
  alignX: 'right',
229
- alignY: 'start' // respected when forcePlacement is true
230
- ,
244
+ alignY: 'start',
231
245
  handleClickOutside: closeMenu,
232
246
  handleEscapeKeydown: closeMenu,
233
247
  handleBackspaceDeleteKeydown: handleBackspaceDeleteKeydown,
@@ -237,16 +251,15 @@ var BlockMenu = function BlockMenu(_ref4) {
237
251
  target: targetHandleRef,
238
252
  zIndex: _editorSharedStyles.akEditorFloatingOverlapPanelZIndex,
239
253
  fitWidth: DEFAULT_MENU_WIDTH,
240
- forcePlacement: true,
241
- preventOverflow: true // disables forced horizontal placement when forcePlacement is on, so fitWidth controls flipping
242
- ,
254
+ fitHeight: menuHeight,
255
+ preventOverflow: true,
243
256
  stick: true,
257
+ offset: [_styles.DRAG_HANDLE_WIDTH + DRAG_HANDLE_OFFSET_PADDING, targetHandleHeightOffset],
244
258
  focusTrap: openedViaKeyboard ?
245
259
  // Only enable focus trap when opened via keyboard to make sure the focus is on the first focusable menu item
246
260
  {
247
261
  initialFocus: undefined
248
- } : undefined,
249
- offset: [_styles.DRAG_HANDLE_WIDTH + DRAG_HANDLE_OFFSET_PADDING, 0]
262
+ } : undefined
250
263
  }, /*#__PURE__*/_react.default.createElement(BlockMenuContent, {
251
264
  api: api,
252
265
  setRef: setRef
@@ -0,0 +1,94 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ const extractNestedLists = (node, listTypes, itemTypes) => {
3
+ const items = [];
4
+ const extract = currentNode => {
5
+ currentNode.forEach(child => {
6
+ // list item -> take content without nested lists, then recurse into nested lists
7
+ if (itemTypes.some(type => child.type === type)) {
8
+ // Filter out nested list nodes from the list item's content
9
+ const contentWithoutNestedLists = [];
10
+ const nestedLists = [];
11
+ child.forEach(grandChild => {
12
+ if (listTypes.some(type => grandChild.type === type)) {
13
+ // This is a nested list - collect it for later processing
14
+ nestedLists.push(grandChild);
15
+ } else {
16
+ // This is regular content (paragraph, etc.) - keep it
17
+ contentWithoutNestedLists.push(grandChild);
18
+ }
19
+ });
20
+
21
+ // Add the list item with only its non-list content
22
+ items.push(child.copy(Fragment.from(contentWithoutNestedLists)));
23
+
24
+ // Now process nested lists to maintain document order
25
+ nestedLists.forEach(nestedList => {
26
+ extract(nestedList);
27
+ });
28
+ }
29
+ // lists -> keep operating
30
+ else if (listTypes.some(type => child.type === type)) {
31
+ extract(child);
32
+ }
33
+ });
34
+ };
35
+ extract(node);
36
+ return items;
37
+ };
38
+
39
+ /**
40
+ * Given an array of nodes, returns an array with the flattened children of any list node
41
+ * to it's first ancestor list, maintaining document order.
42
+ *
43
+ * @example
44
+ * Input:
45
+ * - bulletList
46
+ * - listItem "A"
47
+ * - listItem "B"
48
+ * - bulletList
49
+ * - listItem "C"
50
+ * - listItem "D"
51
+ * - listItem "E"
52
+ *
53
+ * Output:
54
+ * - bulletList
55
+ * - listItem "A"
56
+ * - listItem "B"
57
+ * - listItem "C"
58
+ * - listItem "D"
59
+ * - listItem "E"
60
+ *
61
+ * @example
62
+ * Input (deeply nested):
63
+ * - bulletList
64
+ * - listItem "1"
65
+ * - bulletList
66
+ * - listItem "1.1"
67
+ * - bulletList
68
+ * - listItem "1.1.1"
69
+ * - listItem "1.2"
70
+ * - listItem "2"
71
+ *
72
+ * Output:
73
+ * - bulletList
74
+ * - listItem "1"
75
+ * - listItem "1.1"
76
+ * - listItem "1.1.1"
77
+ * - listItem "1.2"
78
+ * - listItem "2"
79
+ *
80
+ * @param nodes
81
+ * @param context
82
+ * @returns
83
+ *
84
+ * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
85
+ */
86
+ export const flattenListStep = (nodes, context) => {
87
+ const listTypes = [context.schema.nodes.bulletList, context.schema.nodes.orderedList, context.schema.nodes.taskList];
88
+ return nodes.map(node => {
89
+ if (listTypes.some(type => node.type === type)) {
90
+ return node.copy(Fragment.from(extractNestedLists(node, listTypes, [context.schema.nodes.listItem, context.schema.nodes.taskItem])));
91
+ }
92
+ return node;
93
+ });
94
+ };
@@ -0,0 +1,15 @@
1
+ export const flattenStep = (nodes, context) => {
2
+ const {
3
+ schema,
4
+ targetNodeTypeName
5
+ } = context;
6
+
7
+ // TODO: EDITOR-2920 - Implement flattening logic.
8
+ // This is a simplified preliminary approach. We might want to use prosemirror-markdown functions.
9
+ const codeBlockContent = nodes.map(node => node.content.textBetween(0, node.content.size, '\n')).join('\n');
10
+ const outputNode = schema.nodes[targetNodeTypeName].createAndFill({}, schema.text(codeBlockContent));
11
+ if (!outputNode) {
12
+ return nodes;
13
+ }
14
+ return [outputNode];
15
+ };