@atlaskit/editor-plugin-block-menu 5.2.9 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.2.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`eb116a739e7c2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eb116a739e7c2) -
8
+ [ux] Fix bug / make unwrap of expand convert nestedExpand node to regular expand node
9
+
3
10
  ## 5.2.9
4
11
 
5
12
  ### Patch Changes
@@ -48,21 +48,6 @@ var canWrapInTarget = function canWrapInTarget(node, targetNodeType, targetNodeT
48
48
  return targetNodeType.validContent(_model.Fragment.from(node));
49
49
  };
50
50
 
51
- /**
52
- * Converts a nestedExpand to a regular expand node.
53
- * NestedExpands can only exist inside expands, so when breaking out they must be converted.
54
- */
55
- var convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
56
- var _node$attrs;
57
- var expandType = schema.nodes.expand;
58
- if (!expandType) {
59
- return null;
60
- }
61
- return expandType.createAndFill({
62
- title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
63
- }, node.content);
64
- };
65
-
66
51
  /**
67
52
  * A wrap step that handles mixed content according to the Compatibility Matrix:
68
53
  * - Wraps consecutive compatible nodes into the target container
@@ -108,14 +93,6 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
108
93
  // This handles: "If there's a panel in the expand, it breaks out into a separate panel"
109
94
  flushCurrentContainer();
110
95
  result.push(node);
111
- } else if (node.type.name === 'nestedExpand') {
112
- // NestedExpand can't be wrapped and can't exist outside an expand
113
- // Convert to regular expand and break out
114
- flushCurrentContainer();
115
- var expandNode = convertNestedExpandToExpand(node, schema);
116
- if (expandNode) {
117
- result.push(expandNode);
118
- }
119
96
  } else if (isTextNode(node)) {
120
97
  // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
121
98
  // Example: heading can't go in blockquote, so convert to paragraph with same content
@@ -1,17 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.unwrapExpandStep = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
7
  var _unwrapStep = require("./unwrapStep");
8
+ var _utils = require("./utils");
10
9
  /**
11
10
  * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
12
11
  * and prepending it to the children.
13
12
  *
13
+ * Any nestedExpand children are converted to regular expands since nestedExpand
14
+ * can only exist inside an expand.
15
+ *
14
16
  * Example: expand({ title: 'title' })(p('b')) → [p('title'), p('b')]
17
+ * Example: expand({ title: 'outer' })(nestedExpand({ title: 'inner' })(p('x')))
18
+ * → [p('outer'), expand({ title: 'inner' })(p('x'))]
15
19
  */
16
20
  var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(nodes, context) {
17
21
  var schema = context.schema;
@@ -33,8 +37,20 @@ var unwrapExpandStep = exports.unwrapExpandStep = function unwrapExpandStep(node
33
37
  }
34
38
  }
35
39
 
36
- // Add the children
37
- outputNodes.push.apply(outputNodes, (0, _toConsumableArray2.default)(node.children));
40
+ // Add the children, converting any nestedExpands to regular expands
41
+ // since nestedExpand can only exist inside an expand
42
+ node.children.forEach(function (child) {
43
+ if (child.type.name === nestedExpand.name) {
44
+ var expandNode = (0, _utils.convertNestedExpandToExpand)(child, schema);
45
+ if (expandNode) {
46
+ outputNodes.push(expandNode);
47
+ } else {
48
+ outputNodes.push(child);
49
+ }
50
+ } else {
51
+ outputNodes.push(child);
52
+ }
53
+ });
38
54
  } else {
39
55
  (0, _unwrapStep.unwrapStep)([node], context);
40
56
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isListType = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.expandSelectionToBlockRange = void 0;
6
+ exports.isListType = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.getBlockNodesInRange = exports.expandSelectionToBlockRange = exports.convertNestedExpandToExpand = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -112,6 +112,22 @@ var isListType = exports.isListType = function isListType(node, schema) {
112
112
  return list === node.type;
113
113
  });
114
114
  };
115
+
116
+ /**
117
+ * Converts a nestedExpand to a regular expand node.
118
+ * NestedExpands can only exist inside expands, so when breaking out or placing
119
+ * in containers that don't support nesting, they must be converted.
120
+ */
121
+ var convertNestedExpandToExpand = exports.convertNestedExpandToExpand = function convertNestedExpandToExpand(node, schema) {
122
+ var _node$attrs;
123
+ var expandType = schema.nodes.expand;
124
+ if (!expandType) {
125
+ return null;
126
+ }
127
+ return expandType.createAndFill({
128
+ title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
129
+ }, node.content);
130
+ };
115
131
  var getBlockNodesInRange = exports.getBlockNodesInRange = function getBlockNodesInRange(range) {
116
132
  if (range.endIndex - range.startIndex <= 1) {
117
133
  return [range.parent.child(range.startIndex)];
@@ -43,21 +43,6 @@ const canWrapInTarget = (node, targetNodeType, targetNodeTypeName) => {
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
- const convertNestedExpandToExpand = (node, schema) => {
51
- var _node$attrs;
52
- const 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
@@ -105,14 +90,6 @@ export const wrapMixedContentStep = (nodes, context) => {
105
90
  // This handles: "If there's a panel in the expand, it breaks out into a separate panel"
106
91
  flushCurrentContainer();
107
92
  result.push(node);
108
- } else if (node.type.name === 'nestedExpand') {
109
- // NestedExpand can't be wrapped and can't exist outside an expand
110
- // Convert to regular expand and break out
111
- flushCurrentContainer();
112
- const expandNode = convertNestedExpandToExpand(node, schema);
113
- if (expandNode) {
114
- result.push(expandNode);
115
- }
116
93
  } else if (isTextNode(node)) {
117
94
  // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
118
95
  // Example: heading can't go in blockquote, so convert to paragraph with same content
@@ -1,10 +1,16 @@
1
1
  import { unwrapStep } from './unwrapStep';
2
+ import { convertNestedExpandToExpand } from './utils';
2
3
 
3
4
  /**
4
5
  * Unwraps an expand/nestedExpand node, converting its title attribute to a paragraph
5
6
  * and prepending it to the children.
6
7
  *
8
+ * Any nestedExpand children are converted to regular expands since nestedExpand
9
+ * can only exist inside an expand.
10
+ *
7
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'))]
8
14
  */
9
15
  export const unwrapExpandStep = (nodes, context) => {
10
16
  const {
@@ -29,8 +35,20 @@ export const unwrapExpandStep = (nodes, context) => {
29
35
  }
30
36
  }
31
37
 
32
- // Add the children
33
- outputNodes.push(...node.children);
38
+ // Add the children, converting any nestedExpands to regular expands
39
+ // since nestedExpand can only exist inside an expand
40
+ node.children.forEach(child => {
41
+ if (child.type.name === nestedExpand.name) {
42
+ const expandNode = convertNestedExpandToExpand(child, schema);
43
+ if (expandNode) {
44
+ outputNodes.push(expandNode);
45
+ } else {
46
+ outputNodes.push(child);
47
+ }
48
+ } else {
49
+ outputNodes.push(child);
50
+ }
51
+ });
34
52
  } else {
35
53
  unwrapStep([node], context);
36
54
  }
@@ -107,6 +107,22 @@ export const isListType = (node, schema) => {
107
107
  const lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
108
108
  return lists.some(list => list === node.type);
109
109
  };
110
+
111
+ /**
112
+ * Converts a nestedExpand to a regular expand node.
113
+ * NestedExpands can only exist inside expands, so when breaking out or placing
114
+ * in containers that don't support nesting, they must be converted.
115
+ */
116
+ export const convertNestedExpandToExpand = (node, schema) => {
117
+ var _node$attrs;
118
+ const expandType = schema.nodes.expand;
119
+ if (!expandType) {
120
+ return null;
121
+ }
122
+ return expandType.createAndFill({
123
+ title: ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.title) || ''
124
+ }, node.content);
125
+ };
110
126
  export const getBlockNodesInRange = range => {
111
127
  if (range.endIndex - range.startIndex <= 1) {
112
128
  return [range.parent.child(range.startIndex)];
@@ -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.9",
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
  },