@atlaskit/editor-plugin-block-menu 3.1.3 → 3.1.4

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
+ ## 3.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f2000345dec2c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2000345dec2c) -
8
+ ED-29258 Break up list items into new lines when converted into codeblock
9
+
3
10
  ## 3.1.3
4
11
 
5
12
  ### Patch Changes
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.unwrapAndConvertToList = exports.unwrapAndConvertToBlockType = exports.transformToContainer = exports.transformContainerNode = exports.transformBetweenContainerTypes = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _model = require("@atlaskit/editor-prosemirror/model");
10
- var _utils = require("./utils");
10
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
11
+ var _inlineNodeTransforms = require("./inline-node-transforms");
12
+ var _utils2 = require("./utils");
11
13
  var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
12
14
  var validTransformedContent = [];
13
15
  // Headings are not valid inside headings so convert heading nodes to paragraphs
@@ -34,7 +36,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
34
36
  var content = selection.content().content;
35
37
  var transformedContent = content;
36
38
  if (sourceNode.type === schema.nodes.codeBlock) {
37
- var paragraphNodes = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
39
+ var paragraphNodes = (0, _utils2.convertCodeBlockContentToParagraphs)(sourceNode, schema);
38
40
  transformedContent = _model.Fragment.fromArray(paragraphNodes);
39
41
  }
40
42
  if (targetNodeType === schema.nodes.blockquote) {
@@ -45,7 +47,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
45
47
  // e.g. blocks (heading/ paragraph) with alignment need to remove alignment
46
48
  // as panel/ blockQuote/ expands does not support alignment
47
49
  if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
48
- transformedContent = (0, _utils.filterMarksForTargetNodeType)(transformedContent, targetNodeType);
50
+ transformedContent = (0, _utils2.filterMarksForTargetNodeType)(transformedContent, targetNodeType);
49
51
  }
50
52
  var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent);
51
53
  if (!newNode) {
@@ -69,7 +71,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
69
71
  }
70
72
 
71
73
  // Transform container to block type - unwrap and convert content
72
- if ((0, _utils.isBlockNodeType)(targetNodeType)) {
74
+ if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
73
75
  // special case container to codeblock
74
76
  if (targetNodeType.name === 'codeBlock') {
75
77
  return transformBetweenContainerTypes({
@@ -90,7 +92,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
90
92
  }
91
93
 
92
94
  // Transform container to list type
93
- if ((0, _utils.isListNodeType)(targetNodeType)) {
95
+ if ((0, _utils2.isListNodeType)(targetNodeType)) {
94
96
  return unwrapAndConvertToList({
95
97
  tr: tr,
96
98
  sourceNode: sourceNode,
@@ -101,7 +103,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
101
103
  }
102
104
 
103
105
  // Transform between container types
104
- if ((0, _utils.isContainerNodeType)(targetNodeType)) {
106
+ if ((0, _utils2.isContainerNodeType)(targetNodeType)) {
105
107
  return transformBetweenContainerTypes({
106
108
  tr: tr,
107
109
  sourceNode: sourceNode,
@@ -146,7 +148,7 @@ var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function
146
148
 
147
149
  // if the container is a code block, convert text content to multiple paragraphs
148
150
  if (sourceNode.type === codeBlock) {
149
- sourceChildren = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
151
+ sourceChildren = (0, _utils2.convertCodeBlockContentToParagraphs)(sourceNode, schema);
150
152
  }
151
153
 
152
154
  // if target node is a paragraph, just do unwrap
@@ -274,7 +276,7 @@ var transformBetweenContainerTypes = exports.transformBetweenContainerTypes = fu
274
276
  }
275
277
 
276
278
  // Get content validation for target container type
277
- var isContentSupported = (0, _utils.getContentSupportChecker)(targetNodeType);
279
+ var isContentSupported = (0, _utils2.getContentSupportChecker)(targetNodeType);
278
280
 
279
281
  // Process content and collect splits
280
282
  var contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
@@ -334,15 +336,25 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
334
336
  currentTextContent.push(childNode.textContent);
335
337
  } else if (childNode.isTextblock) {
336
338
  // Extract text from text blocks (paragraphs, headings, etc.)
337
- var text = childNode.textContent;
339
+ var text = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(childNode));
338
340
  if (text.trim()) {
339
341
  currentTextContent.push(text);
340
342
  }
341
343
  }
342
- } else if ((0, _utils.isBlockNodeForExtraction)(childNode)) {
344
+ } else if ((0, _utils2.isBlockNodeForExtraction)(childNode)) {
343
345
  // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
344
346
  flushCurrentCodeBlock();
345
347
  splits.push(childNode);
348
+ } else if ((0, _utils2.isListNodeType)(childNode.type)) {
349
+ var isTaskList = childNode.type.name === 'taskList';
350
+ var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
351
+ var listItems = (0, _utils.findChildrenByType)(childNode, listItemType);
352
+ listItems.forEach(function (listItem) {
353
+ var inlineContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(isTaskList ? _model.Fragment.from(listItem.node) : listItem.node.content);
354
+ if (inlineContent.trim()) {
355
+ currentTextContent.push(inlineContent);
356
+ }
357
+ });
346
358
  } else {
347
359
  // Other unsupported content - try to extract text if possible
348
360
  var _text = childNode.textContent;
@@ -394,7 +406,7 @@ var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupported
394
406
  splits.push(childNode);
395
407
  } else {
396
408
  // Unsupported inline content - convert to paragraph and add to container
397
- var inlineContent = (0, _utils.convertNodeToInlineContent)(childNode, schema);
409
+ var inlineContent = (0, _utils2.convertNodeToInlineContent)(childNode, schema);
398
410
  if (inlineContent.length > 0) {
399
411
  var paragraph = schema.nodes.paragraph.create({}, _model.Fragment.fromArray(inlineContent));
400
412
  currentContainerContent.push(paragraph);
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
2
2
  "use strict";
3
3
 
4
4
  var _typeof = require("@babel/runtime/helpers/typeof");
@@ -1,4 +1,6 @@
1
1
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
+ import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
3
+ import { getInlineNodeTextContent } from './inline-node-transforms';
2
4
  import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
3
5
  const convertInvalidNodeToValidNodeType = (sourceContent, sourceNodeType, validNodeType, withMarks) => {
4
6
  const validTransformedContent = [];
@@ -335,7 +337,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
335
337
  currentTextContent.push(childNode.textContent);
336
338
  } else if (childNode.isTextblock) {
337
339
  // Extract text from text blocks (paragraphs, headings, etc.)
338
- const text = childNode.textContent;
340
+ const text = getInlineNodeTextContent(Fragment.from(childNode));
339
341
  if (text.trim()) {
340
342
  currentTextContent.push(text);
341
343
  }
@@ -344,6 +346,16 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
344
346
  // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
345
347
  flushCurrentCodeBlock();
346
348
  splits.push(childNode);
349
+ } else if (isListNodeType(childNode.type)) {
350
+ const isTaskList = childNode.type.name === 'taskList';
351
+ const listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
352
+ const listItems = findChildrenByType(childNode, listItemType);
353
+ listItems.forEach(listItem => {
354
+ const inlineContent = getInlineNodeTextContent(isTaskList ? Fragment.from(listItem.node) : listItem.node.content);
355
+ if (inlineContent.trim()) {
356
+ currentTextContent.push(inlineContent);
357
+ }
358
+ });
347
359
  } else {
348
360
  // Other unsupported content - try to extract text if possible
349
361
  const text = childNode.textContent;
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.36.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';
@@ -1,5 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
+ import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
4
+ import { getInlineNodeTextContent } from './inline-node-transforms';
3
5
  import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
4
6
  var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
5
7
  var validTransformedContent = [];
@@ -327,7 +329,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
327
329
  currentTextContent.push(childNode.textContent);
328
330
  } else if (childNode.isTextblock) {
329
331
  // Extract text from text blocks (paragraphs, headings, etc.)
330
- var text = childNode.textContent;
332
+ var text = getInlineNodeTextContent(Fragment.from(childNode));
331
333
  if (text.trim()) {
332
334
  currentTextContent.push(text);
333
335
  }
@@ -336,6 +338,16 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
336
338
  // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
337
339
  flushCurrentCodeBlock();
338
340
  splits.push(childNode);
341
+ } else if (isListNodeType(childNode.type)) {
342
+ var isTaskList = childNode.type.name === 'taskList';
343
+ var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
344
+ var listItems = findChildrenByType(childNode, listItemType);
345
+ listItems.forEach(function (listItem) {
346
+ var inlineContent = getInlineNodeTextContent(isTaskList ? Fragment.from(listItem.node) : listItem.node.content);
347
+ if (inlineContent.trim()) {
348
+ currentTextContent.push(inlineContent);
349
+ }
350
+ });
339
351
  } else {
340
352
  // Other unsupported content - try to extract text if possible
341
353
  var _text = childNode.textContent;
@@ -1,4 +1,4 @@
1
- /* block-menu.tsx generated by @compiled/babel-plugin v0.38.1 */
1
+ /* block-menu.tsx generated by @compiled/babel-plugin v0.36.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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",