@atlaskit/editor-plugin-block-menu 1.0.10 → 1.0.11

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,15 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 1.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fcef7ff2e1083`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fcef7ff2e1083) -
8
+ Split unsupported content when converting to codeblock
9
+ - [`1754f5027f568`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1754f5027f568) -
10
+ Fix missing copy link on table node
11
+ - Updated dependencies
12
+
3
13
  ## 1.0.10
4
14
 
5
15
  ### Patch Changes
@@ -82,6 +82,16 @@ var transformContainerNode = exports.transformContainerNode = function transform
82
82
 
83
83
  // Transform container to block type - unwrap and convert content
84
84
  if ((0, _utils.isBlockNodeType)(targetNodeType)) {
85
+ // special case container to codeblock
86
+ if (targetNodeType.name === 'codeBlock') {
87
+ return transformBetweenContainerTypes({
88
+ tr: tr,
89
+ sourceNode: sourceNode,
90
+ sourcePos: sourcePos,
91
+ targetNodeType: targetNodeType,
92
+ targetAttrs: targetAttrs
93
+ });
94
+ }
85
95
  return unwrapAndConvertToBlockType({
86
96
  tr: tr,
87
97
  sourceNode: sourceNode,
@@ -274,18 +284,29 @@ var transformBetweenContainerTypes = exports.transformBetweenContainerTypes = fu
274
284
  targetNodeType = context.targetNodeType,
275
285
  targetAttrs = context.targetAttrs;
276
286
 
287
+ // Special handling for codeBlock target
288
+ if (targetNodeType.name === 'codeBlock') {
289
+ var _contentSplits = splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, tr.doc.type.schema);
290
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, _contentSplits);
291
+ }
292
+
277
293
  // Get content validation for target container type
278
294
  var isContentSupported = (0, _utils.getContentSupportChecker)(targetNodeType);
279
295
 
280
296
  // Process content and collect splits
281
297
  var contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
298
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, contentSplits);
299
+ };
282
300
 
283
- // Replace the original node with the first split
301
+ /**
302
+ * Apply content splits to transaction - shared utility for replacing and inserting splits
303
+ */
304
+ var applySplitsToTransaction = function applySplitsToTransaction(tr, sourcePos, sourceNodeSize, contentSplits) {
284
305
  var insertPos = sourcePos;
285
306
  contentSplits.forEach(function (splitNode, index) {
286
307
  if (index === 0) {
287
308
  // Replace the original node with the first split
288
- tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, splitNode);
309
+ tr.replaceWith(sourcePos, sourcePos + sourceNodeSize, splitNode);
289
310
  insertPos = sourcePos + splitNode.nodeSize;
290
311
  } else {
291
312
  // Insert additional splits after
@@ -296,18 +317,75 @@ var transformBetweenContainerTypes = exports.transformBetweenContainerTypes = fu
296
317
  return tr;
297
318
  };
298
319
 
320
+ /**
321
+ * Split content for codeBlock transformation, creating codeBlocks for text content
322
+ * and preserving unsupported blocks (like tables) separately
323
+ */
324
+ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, schema) {
325
+ var _sourceNode$attrs3;
326
+ var splits = [];
327
+ var children = sourceNode.content.content;
328
+ var currentTextContent = [];
329
+
330
+ // Handle expand title - add as first text if source is expand with title
331
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
332
+ currentTextContent.push(sourceNode.attrs.title);
333
+ }
334
+ var flushCurrentCodeBlock = function flushCurrentCodeBlock() {
335
+ if (currentTextContent.length > 0) {
336
+ var codeText = currentTextContent.join('\n');
337
+ var codeBlockNode = targetNodeType.create(targetAttrs, schema.text(codeText));
338
+ splits.push(codeBlockNode);
339
+ currentTextContent = [];
340
+ }
341
+ };
342
+ var isCodeBlockCompatible = function isCodeBlockCompatible(node) {
343
+ // Only text blocks (paragraph, heading) can be converted to codeBlock text
344
+ return node.isTextblock || node.type.name === 'codeBlock';
345
+ };
346
+ children.forEach(function (childNode) {
347
+ if (isCodeBlockCompatible(childNode)) {
348
+ // Extract text content from compatible nodes
349
+ if (childNode.type.name === 'codeBlock') {
350
+ // If it's already a codeBlock, extract its text
351
+ currentTextContent.push(childNode.textContent);
352
+ } else if (childNode.isTextblock) {
353
+ // Extract text from text blocks (paragraphs, headings, etc.)
354
+ var text = childNode.textContent;
355
+ if (text.trim()) {
356
+ currentTextContent.push(text);
357
+ }
358
+ }
359
+ } else if ((0, _utils.isBlockNodeForExtraction)(childNode)) {
360
+ // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
361
+ flushCurrentCodeBlock();
362
+ splits.push(childNode);
363
+ } else {
364
+ // Other unsupported content - try to extract text if possible
365
+ var _text = childNode.textContent;
366
+ if (_text && _text.trim()) {
367
+ currentTextContent.push(_text);
368
+ }
369
+ }
370
+ });
371
+
372
+ // Flush any remaining text content as a codeBlock
373
+ flushCurrentCodeBlock();
374
+ return splits;
375
+ };
376
+
299
377
  /**
300
378
  * Split content around unsupported block nodes, creating separate containers
301
379
  * for content before and after each unsupported block
302
380
  */
303
381
  var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, schema) {
304
- var _sourceNode$attrs3;
382
+ var _sourceNode$attrs4;
305
383
  var splits = [];
306
384
  var children = sourceNode.content.content;
307
385
  var currentContainerContent = [];
308
386
 
309
387
  // Handle expand title - add as first paragraph if source is expand with title
310
- if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
388
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs4 = sourceNode.attrs) !== null && _sourceNode$attrs4 !== void 0 && _sourceNode$attrs4.title) {
311
389
  var titleParagraph = schema.nodes.paragraph.create({}, schema.text(sourceNode.attrs.title));
312
390
  currentContainerContent.push(titleParagraph);
313
391
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isNestedNode = void 0;
7
7
  var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var _editorTables = require("@atlaskit/editor-tables");
8
9
  /**
9
10
  * Determines if a node is nested (not at top-level) based on its depth and context.
10
11
  *
@@ -37,6 +38,11 @@ var isNestedNode = exports.isNestedNode = function isNestedNode(selection) {
37
38
  return true;
38
39
  }
39
40
 
41
+ // Special case for table selection
42
+ if (selection instanceof _editorTables.CellSelection) {
43
+ return depth > 3;
44
+ }
45
+
40
46
  // Check parent node type for depth 2-3
41
47
  var parentNode = $from.node(depth - 1);
42
48
  if (!parentNode) {
@@ -76,6 +76,16 @@ export const transformContainerNode = ({
76
76
 
77
77
  // Transform container to block type - unwrap and convert content
78
78
  if (isBlockNodeType(targetNodeType)) {
79
+ // special case container to codeblock
80
+ if (targetNodeType.name === 'codeBlock') {
81
+ return transformBetweenContainerTypes({
82
+ tr,
83
+ sourceNode,
84
+ sourcePos,
85
+ targetNodeType,
86
+ targetAttrs
87
+ });
88
+ }
79
89
  return unwrapAndConvertToBlockType({
80
90
  tr,
81
91
  sourceNode,
@@ -273,18 +283,29 @@ export const transformBetweenContainerTypes = context => {
273
283
  targetAttrs
274
284
  } = context;
275
285
 
286
+ // Special handling for codeBlock target
287
+ if (targetNodeType.name === 'codeBlock') {
288
+ const contentSplits = splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, tr.doc.type.schema);
289
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, contentSplits);
290
+ }
291
+
276
292
  // Get content validation for target container type
277
293
  const isContentSupported = getContentSupportChecker(targetNodeType);
278
294
 
279
295
  // Process content and collect splits
280
296
  const contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
297
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, contentSplits);
298
+ };
281
299
 
282
- // Replace the original node with the first split
300
+ /**
301
+ * Apply content splits to transaction - shared utility for replacing and inserting splits
302
+ */
303
+ const applySplitsToTransaction = (tr, sourcePos, sourceNodeSize, contentSplits) => {
283
304
  let insertPos = sourcePos;
284
305
  contentSplits.forEach((splitNode, index) => {
285
306
  if (index === 0) {
286
307
  // Replace the original node with the first split
287
- tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, splitNode);
308
+ tr.replaceWith(sourcePos, sourcePos + sourceNodeSize, splitNode);
288
309
  insertPos = sourcePos + splitNode.nodeSize;
289
310
  } else {
290
311
  // Insert additional splits after
@@ -295,18 +316,75 @@ export const transformBetweenContainerTypes = context => {
295
316
  return tr;
296
317
  };
297
318
 
319
+ /**
320
+ * Split content for codeBlock transformation, creating codeBlocks for text content
321
+ * and preserving unsupported blocks (like tables) separately
322
+ */
323
+ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schema) => {
324
+ var _sourceNode$attrs3;
325
+ const splits = [];
326
+ const children = sourceNode.content.content;
327
+ let currentTextContent = [];
328
+
329
+ // Handle expand title - add as first text if source is expand with title
330
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
331
+ currentTextContent.push(sourceNode.attrs.title);
332
+ }
333
+ const flushCurrentCodeBlock = () => {
334
+ if (currentTextContent.length > 0) {
335
+ const codeText = currentTextContent.join('\n');
336
+ const codeBlockNode = targetNodeType.create(targetAttrs, schema.text(codeText));
337
+ splits.push(codeBlockNode);
338
+ currentTextContent = [];
339
+ }
340
+ };
341
+ const isCodeBlockCompatible = node => {
342
+ // Only text blocks (paragraph, heading) can be converted to codeBlock text
343
+ return node.isTextblock || node.type.name === 'codeBlock';
344
+ };
345
+ children.forEach(childNode => {
346
+ if (isCodeBlockCompatible(childNode)) {
347
+ // Extract text content from compatible nodes
348
+ if (childNode.type.name === 'codeBlock') {
349
+ // If it's already a codeBlock, extract its text
350
+ currentTextContent.push(childNode.textContent);
351
+ } else if (childNode.isTextblock) {
352
+ // Extract text from text blocks (paragraphs, headings, etc.)
353
+ const text = childNode.textContent;
354
+ if (text.trim()) {
355
+ currentTextContent.push(text);
356
+ }
357
+ }
358
+ } else if (isBlockNodeForExtraction(childNode)) {
359
+ // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
360
+ flushCurrentCodeBlock();
361
+ splits.push(childNode);
362
+ } else {
363
+ // Other unsupported content - try to extract text if possible
364
+ const text = childNode.textContent;
365
+ if (text && text.trim()) {
366
+ currentTextContent.push(text);
367
+ }
368
+ }
369
+ });
370
+
371
+ // Flush any remaining text content as a codeBlock
372
+ flushCurrentCodeBlock();
373
+ return splits;
374
+ };
375
+
298
376
  /**
299
377
  * Split content around unsupported block nodes, creating separate containers
300
378
  * for content before and after each unsupported block
301
379
  */
302
380
  const splitContentAroundUnsupportedBlocks = (sourceNode, isContentSupported, targetNodeType, targetAttrs, schema) => {
303
- var _sourceNode$attrs3;
381
+ var _sourceNode$attrs4;
304
382
  const splits = [];
305
383
  const children = sourceNode.content.content;
306
384
  let currentContainerContent = [];
307
385
 
308
386
  // Handle expand title - add as first paragraph if source is expand with title
309
- if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
387
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs4 = sourceNode.attrs) !== null && _sourceNode$attrs4 !== void 0 && _sourceNode$attrs4.title) {
310
388
  const titleParagraph = schema.nodes.paragraph.create({}, schema.text(sourceNode.attrs.title));
311
389
  currentContainerContent.push(titleParagraph);
312
390
  }
@@ -1,4 +1,5 @@
1
1
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { CellSelection } from '@atlaskit/editor-tables';
2
3
 
3
4
  /**
4
5
  * Determines if a node is nested (not at top-level) based on its depth and context.
@@ -34,6 +35,11 @@ export const isNestedNode = selection => {
34
35
  return true;
35
36
  }
36
37
 
38
+ // Special case for table selection
39
+ if (selection instanceof CellSelection) {
40
+ return depth > 3;
41
+ }
42
+
37
43
  // Check parent node type for depth 2-3
38
44
  const parentNode = $from.node(depth - 1);
39
45
  if (!parentNode) {
@@ -75,6 +75,16 @@ export var transformContainerNode = function transformContainerNode(_ref2) {
75
75
 
76
76
  // Transform container to block type - unwrap and convert content
77
77
  if (isBlockNodeType(targetNodeType)) {
78
+ // special case container to codeblock
79
+ if (targetNodeType.name === 'codeBlock') {
80
+ return transformBetweenContainerTypes({
81
+ tr: tr,
82
+ sourceNode: sourceNode,
83
+ sourcePos: sourcePos,
84
+ targetNodeType: targetNodeType,
85
+ targetAttrs: targetAttrs
86
+ });
87
+ }
78
88
  return unwrapAndConvertToBlockType({
79
89
  tr: tr,
80
90
  sourceNode: sourceNode,
@@ -267,18 +277,29 @@ export var transformBetweenContainerTypes = function transformBetweenContainerTy
267
277
  targetNodeType = context.targetNodeType,
268
278
  targetAttrs = context.targetAttrs;
269
279
 
280
+ // Special handling for codeBlock target
281
+ if (targetNodeType.name === 'codeBlock') {
282
+ var _contentSplits = splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, tr.doc.type.schema);
283
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, _contentSplits);
284
+ }
285
+
270
286
  // Get content validation for target container type
271
287
  var isContentSupported = getContentSupportChecker(targetNodeType);
272
288
 
273
289
  // Process content and collect splits
274
290
  var contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
291
+ return applySplitsToTransaction(tr, sourcePos, sourceNode.nodeSize, contentSplits);
292
+ };
275
293
 
276
- // Replace the original node with the first split
294
+ /**
295
+ * Apply content splits to transaction - shared utility for replacing and inserting splits
296
+ */
297
+ var applySplitsToTransaction = function applySplitsToTransaction(tr, sourcePos, sourceNodeSize, contentSplits) {
277
298
  var insertPos = sourcePos;
278
299
  contentSplits.forEach(function (splitNode, index) {
279
300
  if (index === 0) {
280
301
  // Replace the original node with the first split
281
- tr.replaceWith(sourcePos, sourcePos + sourceNode.nodeSize, splitNode);
302
+ tr.replaceWith(sourcePos, sourcePos + sourceNodeSize, splitNode);
282
303
  insertPos = sourcePos + splitNode.nodeSize;
283
304
  } else {
284
305
  // Insert additional splits after
@@ -289,18 +310,75 @@ export var transformBetweenContainerTypes = function transformBetweenContainerTy
289
310
  return tr;
290
311
  };
291
312
 
313
+ /**
314
+ * Split content for codeBlock transformation, creating codeBlocks for text content
315
+ * and preserving unsupported blocks (like tables) separately
316
+ */
317
+ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, targetNodeType, targetAttrs, schema) {
318
+ var _sourceNode$attrs3;
319
+ var splits = [];
320
+ var children = sourceNode.content.content;
321
+ var currentTextContent = [];
322
+
323
+ // Handle expand title - add as first text if source is expand with title
324
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
325
+ currentTextContent.push(sourceNode.attrs.title);
326
+ }
327
+ var flushCurrentCodeBlock = function flushCurrentCodeBlock() {
328
+ if (currentTextContent.length > 0) {
329
+ var codeText = currentTextContent.join('\n');
330
+ var codeBlockNode = targetNodeType.create(targetAttrs, schema.text(codeText));
331
+ splits.push(codeBlockNode);
332
+ currentTextContent = [];
333
+ }
334
+ };
335
+ var isCodeBlockCompatible = function isCodeBlockCompatible(node) {
336
+ // Only text blocks (paragraph, heading) can be converted to codeBlock text
337
+ return node.isTextblock || node.type.name === 'codeBlock';
338
+ };
339
+ children.forEach(function (childNode) {
340
+ if (isCodeBlockCompatible(childNode)) {
341
+ // Extract text content from compatible nodes
342
+ if (childNode.type.name === 'codeBlock') {
343
+ // If it's already a codeBlock, extract its text
344
+ currentTextContent.push(childNode.textContent);
345
+ } else if (childNode.isTextblock) {
346
+ // Extract text from text blocks (paragraphs, headings, etc.)
347
+ var text = childNode.textContent;
348
+ if (text.trim()) {
349
+ currentTextContent.push(text);
350
+ }
351
+ }
352
+ } else if (isBlockNodeForExtraction(childNode)) {
353
+ // Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
354
+ flushCurrentCodeBlock();
355
+ splits.push(childNode);
356
+ } else {
357
+ // Other unsupported content - try to extract text if possible
358
+ var _text = childNode.textContent;
359
+ if (_text && _text.trim()) {
360
+ currentTextContent.push(_text);
361
+ }
362
+ }
363
+ });
364
+
365
+ // Flush any remaining text content as a codeBlock
366
+ flushCurrentCodeBlock();
367
+ return splits;
368
+ };
369
+
292
370
  /**
293
371
  * Split content around unsupported block nodes, creating separate containers
294
372
  * for content before and after each unsupported block
295
373
  */
296
374
  var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, schema) {
297
- var _sourceNode$attrs3;
375
+ var _sourceNode$attrs4;
298
376
  var splits = [];
299
377
  var children = sourceNode.content.content;
300
378
  var currentContainerContent = [];
301
379
 
302
380
  // Handle expand title - add as first paragraph if source is expand with title
303
- if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
381
+ if (sourceNode.type.name === 'expand' && (_sourceNode$attrs4 = sourceNode.attrs) !== null && _sourceNode$attrs4 !== void 0 && _sourceNode$attrs4.title) {
304
382
  var titleParagraph = schema.nodes.paragraph.create({}, schema.text(sourceNode.attrs.title));
305
383
  currentContainerContent.push(titleParagraph);
306
384
  }
@@ -1,4 +1,5 @@
1
1
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { CellSelection } from '@atlaskit/editor-tables';
2
3
 
3
4
  /**
4
5
  * Determines if a node is nested (not at top-level) based on its depth and context.
@@ -32,6 +33,11 @@ export var isNestedNode = function isNestedNode(selection) {
32
33
  return true;
33
34
  }
34
35
 
36
+ // Special case for table selection
37
+ if (selection instanceof CellSelection) {
38
+ return depth > 3;
39
+ }
40
+
35
41
  // Check parent node type for depth 2-3
36
42
  var parentNode = $from.node(depth - 1);
37
43
  if (!parentNode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",