@atlaskit/editor-plugin-block-menu 3.1.0 → 3.1.1

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,13 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c30d1876a650a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c30d1876a650a) -
8
+ ED-29256 Transform content with indentation in layouts
9
+ - Updated dependencies
10
+
3
11
  ## 3.1.0
4
12
 
5
13
  ### Minor Changes
@@ -20,10 +20,16 @@ var unwrapLayoutNodesToTextNodes = exports.unwrapLayoutNodesToTextNodes = functi
20
20
  var isValid = (0, _utils2.getContentSupportChecker)(finalTargetNodeType);
21
21
  var createTextNode = function createTextNode(node) {
22
22
  var isTextNode = node.type.name === 'text';
23
- if (isValid(node) && !isTextNode) {
24
- return node;
23
+ var nodeToTransform = node;
24
+ if ((0, _utils2.isContainerNodeType)(finalTargetNodeType) || (0, _utils2.isListNodeType)(finalTargetNodeType)) {
25
+ nodeToTransform = node.mark(node.marks.filter(function (mark) {
26
+ return !['alignment', 'indentation'].includes(mark.type.name);
27
+ }));
25
28
  }
26
- return targetNodeType.createChecked(targetAttrs, isTextNode ? node : node.content, node.marks);
29
+ if (isValid(nodeToTransform) && !isTextNode) {
30
+ return nodeToTransform;
31
+ }
32
+ return targetNodeType.createChecked(targetAttrs, isTextNode ? nodeToTransform : nodeToTransform.content, nodeToTransform.marks);
27
33
  };
28
34
  if ((0, _utils2.isBlockNode)(sourceNode)) {
29
35
  // code block acts like a container, we need to unwrap it
@@ -190,21 +196,17 @@ var transformToContainerNode = function transformToContainerNode(nodes, targetNo
190
196
  canBeTransformed: false
191
197
  });
192
198
  } else {
193
- // Remove alignment marks as container nodes don't support them
194
- var nodeWithValidAttrs = node.mark(node.marks.filter(function (mark) {
195
- return mark.type.name !== 'alignment';
196
- }));
197
199
  var isSameNodeType = node.type === targetNodeType;
198
200
 
199
201
  // If the node is not valid and not the same type, we cannot transform it
200
- if (!isNodeValid(nodeWithValidAttrs) && !isSameNodeType) {
202
+ if (!isNodeValid(node) && !isSameNodeType) {
201
203
  newNodes.push({
202
204
  node: node,
203
205
  canBeTransformed: false
204
206
  });
205
207
  return;
206
208
  }
207
- var _nodes = isSameNodeType ? node.content.content : [nodeWithValidAttrs];
209
+ var _nodes = isSameNodeType ? node.content.content : [node];
208
210
  if (newNodes.length === 0) {
209
211
  newNodes.push({
210
212
  node: _nodes,
@@ -322,8 +324,20 @@ var transformToListNode = exports.transformToListNode = function transformToList
322
324
  }
323
325
  });
324
326
  };
325
- var convertUnwrappedLayoutContent = exports.convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
326
- if (nodes.length === 1 && nodes[0].content.size === 0) {
327
+ var convertUnwrappedLayoutContent = exports.convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema, targetAttrs) {
328
+ if (nodes.length === 1 && nodes[0].content.size === 0 && !(0, _utils2.isContainerNodeType)(targetNodeType)) {
329
+ if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
330
+ if (['heading', 'paragraph'].includes(targetNodeType.name)) {
331
+ return [targetNodeType.createChecked(targetAttrs)];
332
+ }
333
+ if (targetNodeType.name === 'codeBlock') {
334
+ return [targetNodeType.createChecked()];
335
+ }
336
+ }
337
+ if ((0, _utils2.isListNodeType)(targetNodeType)) {
338
+ var listItem = (0, _transforms.isTaskList)(targetNodeType) ? schema.nodes.taskItem.createChecked() : schema.nodes.listItem.createChecked(null, schema.nodes.paragraph.createChecked());
339
+ return [targetNodeType.createChecked(null, listItem)];
340
+ }
327
341
  return nodes;
328
342
  }
329
343
  if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
@@ -60,7 +60,7 @@ var transformLayoutNode = exports.transformLayoutNode = function transformLayout
60
60
  var newContent = (0, _utils.unwrapLayoutNodesToTextNodes)(context, targetNodeType);
61
61
  unwrappedContent.push.apply(unwrappedContent, (0, _toConsumableArray2.default)(newContent));
62
62
  });
63
- var newColumnContent = (0, _utils.convertUnwrappedLayoutContent)(unwrappedContent, targetNodeType, schema);
63
+ var newColumnContent = (0, _utils.convertUnwrappedLayoutContent)(unwrappedContent, targetNodeType, schema, targetAttrs);
64
64
  layoutColumnNodes.push(layoutColumn.createChecked(child.attrs, _model.Fragment.fromArray(newColumnContent), child.marks));
65
65
  }
66
66
  });
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  "use strict";
3
3
 
4
4
  var _typeof = require("@babel/runtime/helpers/typeof");
@@ -14,10 +14,14 @@ export const unwrapLayoutNodesToTextNodes = (context, finalTargetNodeType) => {
14
14
  const isValid = getContentSupportChecker(finalTargetNodeType);
15
15
  const createTextNode = node => {
16
16
  const isTextNode = node.type.name === 'text';
17
- if (isValid(node) && !isTextNode) {
18
- return node;
17
+ let nodeToTransform = node;
18
+ if (isContainerNodeType(finalTargetNodeType) || isListNodeType(finalTargetNodeType)) {
19
+ nodeToTransform = node.mark(node.marks.filter(mark => !['alignment', 'indentation'].includes(mark.type.name)));
20
+ }
21
+ if (isValid(nodeToTransform) && !isTextNode) {
22
+ return nodeToTransform;
19
23
  }
20
- return targetNodeType.createChecked(targetAttrs, isTextNode ? node : node.content, node.marks);
24
+ return targetNodeType.createChecked(targetAttrs, isTextNode ? nodeToTransform : nodeToTransform.content, nodeToTransform.marks);
21
25
  };
22
26
  if (isBlockNode(sourceNode)) {
23
27
  // code block acts like a container, we need to unwrap it
@@ -169,19 +173,17 @@ const transformToContainerNode = (nodes, targetNodeType) => {
169
173
  canBeTransformed: false
170
174
  });
171
175
  } else {
172
- // Remove alignment marks as container nodes don't support them
173
- const nodeWithValidAttrs = node.mark(node.marks.filter(mark => mark.type.name !== 'alignment'));
174
176
  const isSameNodeType = node.type === targetNodeType;
175
177
 
176
178
  // If the node is not valid and not the same type, we cannot transform it
177
- if (!isNodeValid(nodeWithValidAttrs) && !isSameNodeType) {
179
+ if (!isNodeValid(node) && !isSameNodeType) {
178
180
  newNodes.push({
179
181
  node: node,
180
182
  canBeTransformed: false
181
183
  });
182
184
  return;
183
185
  }
184
- const nodes = isSameNodeType ? node.content.content : [nodeWithValidAttrs];
186
+ const nodes = isSameNodeType ? node.content.content : [node];
185
187
  if (newNodes.length === 0) {
186
188
  newNodes.push({
187
189
  node: nodes,
@@ -301,8 +303,20 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
301
303
  }
302
304
  });
303
305
  };
304
- export const convertUnwrappedLayoutContent = (nodes, targetNodeType, schema) => {
305
- if (nodes.length === 1 && nodes[0].content.size === 0) {
306
+ export const convertUnwrappedLayoutContent = (nodes, targetNodeType, schema, targetAttrs) => {
307
+ if (nodes.length === 1 && nodes[0].content.size === 0 && !isContainerNodeType(targetNodeType)) {
308
+ if (isBlockNodeType(targetNodeType)) {
309
+ if (['heading', 'paragraph'].includes(targetNodeType.name)) {
310
+ return [targetNodeType.createChecked(targetAttrs)];
311
+ }
312
+ if (targetNodeType.name === 'codeBlock') {
313
+ return [targetNodeType.createChecked()];
314
+ }
315
+ }
316
+ if (isListNodeType(targetNodeType)) {
317
+ const listItem = isTaskList(targetNodeType) ? schema.nodes.taskItem.createChecked() : schema.nodes.listItem.createChecked(null, schema.nodes.paragraph.createChecked());
318
+ return [targetNodeType.createChecked(null, listItem)];
319
+ }
306
320
  return nodes;
307
321
  }
308
322
  if (isBlockNodeType(targetNodeType)) {
@@ -56,7 +56,7 @@ export const transformLayoutNode = context => {
56
56
  const newContent = unwrapLayoutNodesToTextNodes(context, targetNodeType);
57
57
  unwrappedContent.push(...newContent);
58
58
  });
59
- const newColumnContent = convertUnwrappedLayoutContent(unwrappedContent, targetNodeType, schema);
59
+ const newColumnContent = convertUnwrappedLayoutContent(unwrappedContent, targetNodeType, schema, targetAttrs);
60
60
  layoutColumnNodes.push(layoutColumn.createChecked(child.attrs, Fragment.fromArray(newColumnContent), child.marks));
61
61
  }
62
62
  });
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  import "./block-menu.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext, useEffect } from 'react';
@@ -13,10 +13,16 @@ export var unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(
13
13
  var isValid = getContentSupportChecker(finalTargetNodeType);
14
14
  var createTextNode = function createTextNode(node) {
15
15
  var isTextNode = node.type.name === 'text';
16
- if (isValid(node) && !isTextNode) {
17
- return node;
16
+ var nodeToTransform = node;
17
+ if (isContainerNodeType(finalTargetNodeType) || isListNodeType(finalTargetNodeType)) {
18
+ nodeToTransform = node.mark(node.marks.filter(function (mark) {
19
+ return !['alignment', 'indentation'].includes(mark.type.name);
20
+ }));
18
21
  }
19
- return targetNodeType.createChecked(targetAttrs, isTextNode ? node : node.content, node.marks);
22
+ if (isValid(nodeToTransform) && !isTextNode) {
23
+ return nodeToTransform;
24
+ }
25
+ return targetNodeType.createChecked(targetAttrs, isTextNode ? nodeToTransform : nodeToTransform.content, nodeToTransform.marks);
20
26
  };
21
27
  if (isBlockNode(sourceNode)) {
22
28
  // code block acts like a container, we need to unwrap it
@@ -183,21 +189,17 @@ var transformToContainerNode = function transformToContainerNode(nodes, targetNo
183
189
  canBeTransformed: false
184
190
  });
185
191
  } else {
186
- // Remove alignment marks as container nodes don't support them
187
- var nodeWithValidAttrs = node.mark(node.marks.filter(function (mark) {
188
- return mark.type.name !== 'alignment';
189
- }));
190
192
  var isSameNodeType = node.type === targetNodeType;
191
193
 
192
194
  // If the node is not valid and not the same type, we cannot transform it
193
- if (!isNodeValid(nodeWithValidAttrs) && !isSameNodeType) {
195
+ if (!isNodeValid(node) && !isSameNodeType) {
194
196
  newNodes.push({
195
197
  node: node,
196
198
  canBeTransformed: false
197
199
  });
198
200
  return;
199
201
  }
200
- var _nodes = isSameNodeType ? node.content.content : [nodeWithValidAttrs];
202
+ var _nodes = isSameNodeType ? node.content.content : [node];
201
203
  if (newNodes.length === 0) {
202
204
  newNodes.push({
203
205
  node: _nodes,
@@ -315,8 +317,20 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
315
317
  }
316
318
  });
317
319
  };
318
- export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
319
- if (nodes.length === 1 && nodes[0].content.size === 0) {
320
+ export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema, targetAttrs) {
321
+ if (nodes.length === 1 && nodes[0].content.size === 0 && !isContainerNodeType(targetNodeType)) {
322
+ if (isBlockNodeType(targetNodeType)) {
323
+ if (['heading', 'paragraph'].includes(targetNodeType.name)) {
324
+ return [targetNodeType.createChecked(targetAttrs)];
325
+ }
326
+ if (targetNodeType.name === 'codeBlock') {
327
+ return [targetNodeType.createChecked()];
328
+ }
329
+ }
330
+ if (isListNodeType(targetNodeType)) {
331
+ var listItem = isTaskList(targetNodeType) ? schema.nodes.taskItem.createChecked() : schema.nodes.listItem.createChecked(null, schema.nodes.paragraph.createChecked());
332
+ return [targetNodeType.createChecked(null, listItem)];
333
+ }
320
334
  return nodes;
321
335
  }
322
336
  if (isBlockNodeType(targetNodeType)) {
@@ -53,7 +53,7 @@ export var transformLayoutNode = function transformLayoutNode(context) {
53
53
  var newContent = unwrapLayoutNodesToTextNodes(context, targetNodeType);
54
54
  unwrappedContent.push.apply(unwrappedContent, _toConsumableArray(newContent));
55
55
  });
56
- var newColumnContent = convertUnwrappedLayoutContent(unwrappedContent, targetNodeType, schema);
56
+ var newColumnContent = convertUnwrappedLayoutContent(unwrappedContent, targetNodeType, schema, targetAttrs);
57
57
  layoutColumnNodes.push(layoutColumn.createChecked(child.attrs, Fragment.fromArray(newColumnContent), child.marks));
58
58
  }
59
59
  });
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  import "./block-menu.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext, useEffect } from 'react';
@@ -2,4 +2,4 @@ import type { TransformContext } from '@atlaskit/editor-common/transforms';
2
2
  import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
3
3
  export declare const unwrapLayoutNodesToTextNodes: (context: TransformContext, finalTargetNodeType: NodeType) => PMNode[];
4
4
  export declare const transformToListNode: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
5
- export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
5
+ export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema, targetAttrs?: TransformContext["targetAttrs"]) => PMNode[];
@@ -2,4 +2,4 @@ import type { TransformContext } from '@atlaskit/editor-common/transforms';
2
2
  import type { NodeType, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
3
3
  export declare const unwrapLayoutNodesToTextNodes: (context: TransformContext, finalTargetNodeType: NodeType) => PMNode[];
4
4
  export declare const transformToListNode: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
5
- export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema) => PMNode[];
5
+ export declare const convertUnwrappedLayoutContent: (nodes: PMNode[], targetNodeType: NodeType, schema: Schema, targetAttrs?: TransformContext["targetAttrs"]) => PMNode[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@atlaskit/css": "^0.14.0",
32
32
  "@atlaskit/dropdown-menu": "^16.3.0",
33
- "@atlaskit/editor-plugin-block-controls": "^6.1.0",
33
+ "@atlaskit/editor-plugin-block-controls": "^6.2.0",
34
34
  "@atlaskit/editor-plugin-decorations": "^5.0.0",
35
35
  "@atlaskit/editor-plugin-selection": "^5.0.0",
36
36
  "@atlaskit/editor-plugin-user-intent": "^3.0.0",
@@ -46,7 +46,7 @@
46
46
  "@babel/runtime": "^7.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@atlaskit/editor-common": "^109.4.0",
49
+ "@atlaskit/editor-common": "^109.5.0",
50
50
  "react": "^18.2.0",
51
51
  "react-intl-next": "npm:react-intl@^5.18.1"
52
52
  },