@atlaskit/editor-plugin-block-controls 2.13.8 → 2.13.9

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-controls
2
2
 
3
+ ## 2.13.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#161549](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/161549)
8
+ [`35e70290e4ccb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/35e70290e4ccb) -
9
+ [ED-25317] Fix the issue where drag handle for layout column does not show up when the content is
10
+ not empty (with non text content)
11
+ - Updated dependencies
12
+
3
13
  ## 2.13.8
4
14
 
5
15
  ### Patch Changes
@@ -11,7 +11,8 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
12
  var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
13
13
  var _decorationsCommon = require("./decorations-common");
14
- var IGNORE_NODES = (0, _advancedLayoutsFlags.isPreRelease2)() ? ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'] : ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
14
+ var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
15
+ var IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
15
16
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
16
17
  var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
17
18
  // Optimisation to avoid drawing node decorations for empty table cells
@@ -23,12 +24,12 @@ var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDesce
23
24
  }
24
25
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
25
26
  };
26
- var shouldIgnoreNode = function shouldIgnoreNode(node) {
27
+ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes) {
27
28
  var isEmbedCard = 'embedCard' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3');
28
29
 
29
30
  // TODO use isWrappedMedia when clean up the feature flag
30
31
  var isMediaSingle = 'mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1');
31
- return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
32
+ return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
32
33
  };
33
34
 
34
35
  /**
@@ -64,6 +65,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
64
65
  var decs = [];
65
66
  var docFrom = from === undefined || from < 0 ? 0 : from;
66
67
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
68
+ var ignore_nodes = (0, _advancedLayoutsFlags.isPreRelease2)() ? IGNORE_NODES_NEXT : IGNORE_NODES;
67
69
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
68
70
  var _Decoration$node;
69
71
  var depth = 0;
@@ -76,7 +78,7 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
76
78
  if (node.isInline) {
77
79
  return false;
78
80
  }
79
- if (shouldIgnoreNode(node)) {
81
+ if (shouldIgnoreNode(node, ignore_nodes)) {
80
82
  return shouldDescend; //skip over, don't consider it a valid depth
81
83
  }
82
84
  depth = newState.doc.resolve(pos).depth;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.handleMouseOver = void 0;
7
- var _whitespace = require("@atlaskit/editor-common/whitespace");
8
7
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
8
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
9
  var _advancedLayoutsFlags = require("../utils/advanced-layouts-flags");
@@ -15,11 +14,19 @@ var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(t
15
14
  }
16
15
  return false;
17
16
  };
18
- var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(target) {
19
- var _target$textContent;
20
- return target instanceof HTMLDivElement && (target === null || target === void 0 ? void 0 : target.getAttribute('data-drag-handler-node-type')) === 'layoutColumn' &&
21
- // Remove placeholder text
22
- ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.replace(new RegExp(_whitespace.ZERO_WIDTH_SPACE, 'g'), '')) === '';
17
+ var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(node) {
18
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
19
+ var foundNonEmptyNode = false;
20
+ for (var i = 0; i < node.childCount; i++) {
21
+ var _child$firstChild;
22
+ var child = node.child(i);
23
+ if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
24
+ foundNonEmptyNode = true;
25
+ break;
26
+ }
27
+ }
28
+ return !foundNonEmptyNode;
29
+ }
23
30
  };
24
31
  var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, event, api) {
25
32
  var _api$blockControls, _target$classList;
@@ -46,10 +53,6 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
46
53
  var parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
47
54
  var parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
48
55
 
49
- // Don't show drag handle when there is no content/only placeholder in layout column
50
- if ((0, _advancedLayoutsFlags.isPreRelease2)() && isLayoutColumnWithoutContent(rootElement)) {
51
- return false;
52
- }
53
56
  // We want to exlude handles from showing for direct decendant of table nodes (i.e. nodes in cells)
54
57
  if (parentElement && parentElementType === 'table' && (0, _experiments.editorExperiment)('nested-dnd', true) && (0, _experiments.editorExperiment)('table-nested-dnd', false, {
55
58
  exposure: true
@@ -84,6 +87,11 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
84
87
  } else {
85
88
  pos = view.posAtDOM(rootElement, 0);
86
89
  }
90
+ var node = view.state.doc.nodeAt(pos);
91
+ if ((0, _advancedLayoutsFlags.isPreRelease2)() && node && isLayoutColumnWithoutContent(node)) {
92
+ // Don't show drag handle when there is no content/only placeholder in layout column
93
+ return false;
94
+ }
87
95
  var rootPos;
88
96
  if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
89
97
  rootPos = view.state.doc.resolve(pos).pos;
@@ -3,7 +3,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
4
  import { isPreRelease2 } from '../utils/advanced-layouts-flags';
5
5
  import { getNestedDepth, getNodeAnchor, TYPE_NODE_DEC } from './decorations-common';
6
- const IGNORE_NODES = isPreRelease2() ? ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'] : ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
6
+ const IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
7
+ const IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
7
8
  const IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
8
9
  export const shouldDescendIntoNode = node => {
9
10
  // Optimisation to avoid drawing node decorations for empty table cells
@@ -15,12 +16,12 @@ export const shouldDescendIntoNode = node => {
15
16
  }
16
17
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
17
18
  };
18
- const shouldIgnoreNode = node => {
19
+ const shouldIgnoreNode = (node, ignore_nodes) => {
19
20
  const isEmbedCard = 'embedCard' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_3');
20
21
 
21
22
  // TODO use isWrappedMedia when clean up the feature flag
22
23
  const isMediaSingle = 'mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1');
23
- return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
24
+ return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
24
25
  };
25
26
 
26
27
  /**
@@ -54,6 +55,7 @@ export const nodeDecorations = (newState, from, to) => {
54
55
  const decs = [];
55
56
  const docFrom = from === undefined || from < 0 ? 0 : from;
56
57
  const docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
58
+ const ignore_nodes = isPreRelease2() ? IGNORE_NODES_NEXT : IGNORE_NODES;
57
59
  newState.doc.nodesBetween(docFrom, docTo, (node, pos, _parent, index) => {
58
60
  let depth = 0;
59
61
  let anchorName;
@@ -65,7 +67,7 @@ export const nodeDecorations = (newState, from, to) => {
65
67
  if (node.isInline) {
66
68
  return false;
67
69
  }
68
- if (shouldIgnoreNode(node)) {
70
+ if (shouldIgnoreNode(node, ignore_nodes)) {
69
71
  return shouldDescend; //skip over, don't consider it a valid depth
70
72
  }
71
73
  depth = newState.doc.resolve(pos).depth;
@@ -1,4 +1,3 @@
1
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
2
1
  import { fg } from '@atlaskit/platform-feature-flags';
3
2
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
3
  import { isPreRelease2 } from '../utils/advanced-layouts-flags';
@@ -9,11 +8,19 @@ const isEmptyNestedParagraphOrHeading = target => {
9
8
  }
10
9
  return false;
11
10
  };
12
- const isLayoutColumnWithoutContent = target => {
13
- var _target$textContent;
14
- return target instanceof HTMLDivElement && (target === null || target === void 0 ? void 0 : target.getAttribute('data-drag-handler-node-type')) === 'layoutColumn' &&
15
- // Remove placeholder text
16
- ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.replace(new RegExp(ZERO_WIDTH_SPACE, 'g'), '')) === '';
11
+ const isLayoutColumnWithoutContent = node => {
12
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
13
+ let foundNonEmptyNode = false;
14
+ for (let i = 0; i < node.childCount; i++) {
15
+ var _child$firstChild;
16
+ const child = node.child(i);
17
+ if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
18
+ foundNonEmptyNode = true;
19
+ break;
20
+ }
21
+ }
22
+ return !foundNonEmptyNode;
23
+ }
17
24
  };
18
25
  export const handleMouseOver = (view, event, api) => {
19
26
  var _api$blockControls, _target$classList;
@@ -41,10 +48,6 @@ export const handleMouseOver = (view, event, api) => {
41
48
  const parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
42
49
  const parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
43
50
 
44
- // Don't show drag handle when there is no content/only placeholder in layout column
45
- if (isPreRelease2() && isLayoutColumnWithoutContent(rootElement)) {
46
- return false;
47
- }
48
51
  // We want to exlude handles from showing for direct decendant of table nodes (i.e. nodes in cells)
49
52
  if (parentElement && parentElementType === 'table' && editorExperiment('nested-dnd', true) && editorExperiment('table-nested-dnd', false, {
50
53
  exposure: true
@@ -79,6 +82,11 @@ export const handleMouseOver = (view, event, api) => {
79
82
  } else {
80
83
  pos = view.posAtDOM(rootElement, 0);
81
84
  }
85
+ const node = view.state.doc.nodeAt(pos);
86
+ if (isPreRelease2() && node && isLayoutColumnWithoutContent(node)) {
87
+ // Don't show drag handle when there is no content/only placeholder in layout column
88
+ return false;
89
+ }
82
90
  let rootPos;
83
91
  if (editorExperiment('nested-dnd', true)) {
84
92
  rootPos = view.state.doc.resolve(pos).pos;
@@ -4,7 +4,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
4
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
5
  import { isPreRelease2 } from '../utils/advanced-layouts-flags';
6
6
  import { getNestedDepth, getNodeAnchor, TYPE_NODE_DEC } from './decorations-common';
7
- var IGNORE_NODES = isPreRelease2() ? ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'] : ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
7
+ var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption', 'layoutColumn'];
8
+ var IGNORE_NODES_NEXT = ['tableCell', 'tableHeader', 'tableRow', 'listItem', 'caption'];
8
9
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
9
10
  export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
10
11
  // Optimisation to avoid drawing node decorations for empty table cells
@@ -16,12 +17,12 @@ export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
16
17
  }
17
18
  return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
18
19
  };
19
- var shouldIgnoreNode = function shouldIgnoreNode(node) {
20
+ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes) {
20
21
  var isEmbedCard = 'embedCard' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_3');
21
22
 
22
23
  // TODO use isWrappedMedia when clean up the feature flag
23
24
  var isMediaSingle = 'mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1');
24
- return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
25
+ return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
25
26
  };
26
27
 
27
28
  /**
@@ -57,6 +58,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
57
58
  var decs = [];
58
59
  var docFrom = from === undefined || from < 0 ? 0 : from;
59
60
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
61
+ var ignore_nodes = isPreRelease2() ? IGNORE_NODES_NEXT : IGNORE_NODES;
60
62
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
61
63
  var _Decoration$node;
62
64
  var depth = 0;
@@ -69,7 +71,7 @@ export var nodeDecorations = function nodeDecorations(newState, from, to) {
69
71
  if (node.isInline) {
70
72
  return false;
71
73
  }
72
- if (shouldIgnoreNode(node)) {
74
+ if (shouldIgnoreNode(node, ignore_nodes)) {
73
75
  return shouldDescend; //skip over, don't consider it a valid depth
74
76
  }
75
77
  depth = newState.doc.resolve(pos).depth;
@@ -1,4 +1,3 @@
1
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
2
1
  import { fg } from '@atlaskit/platform-feature-flags';
3
2
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
3
  import { isPreRelease2 } from '../utils/advanced-layouts-flags';
@@ -9,11 +8,19 @@ var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(t
9
8
  }
10
9
  return false;
11
10
  };
12
- var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(target) {
13
- var _target$textContent;
14
- return target instanceof HTMLDivElement && (target === null || target === void 0 ? void 0 : target.getAttribute('data-drag-handler-node-type')) === 'layoutColumn' &&
15
- // Remove placeholder text
16
- ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.replace(new RegExp(ZERO_WIDTH_SPACE, 'g'), '')) === '';
11
+ var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(node) {
12
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
13
+ var foundNonEmptyNode = false;
14
+ for (var i = 0; i < node.childCount; i++) {
15
+ var _child$firstChild;
16
+ var child = node.child(i);
17
+ if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
18
+ foundNonEmptyNode = true;
19
+ break;
20
+ }
21
+ }
22
+ return !foundNonEmptyNode;
23
+ }
17
24
  };
18
25
  export var handleMouseOver = function handleMouseOver(view, event, api) {
19
26
  var _api$blockControls, _target$classList;
@@ -40,10 +47,6 @@ export var handleMouseOver = function handleMouseOver(view, event, api) {
40
47
  var parentElement = (_rootElement$parentEl = rootElement.parentElement) === null || _rootElement$parentEl === void 0 ? void 0 : _rootElement$parentEl.closest('[data-drag-handler-anchor-name]');
41
48
  var parentElementType = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('data-drag-handler-node-type');
42
49
 
43
- // Don't show drag handle when there is no content/only placeholder in layout column
44
- if (isPreRelease2() && isLayoutColumnWithoutContent(rootElement)) {
45
- return false;
46
- }
47
50
  // We want to exlude handles from showing for direct decendant of table nodes (i.e. nodes in cells)
48
51
  if (parentElement && parentElementType === 'table' && editorExperiment('nested-dnd', true) && editorExperiment('table-nested-dnd', false, {
49
52
  exposure: true
@@ -78,6 +81,11 @@ export var handleMouseOver = function handleMouseOver(view, event, api) {
78
81
  } else {
79
82
  pos = view.posAtDOM(rootElement, 0);
80
83
  }
84
+ var node = view.state.doc.nodeAt(pos);
85
+ if (isPreRelease2() && node && isLayoutColumnWithoutContent(node)) {
86
+ // Don't show drag handle when there is no content/only placeholder in layout column
87
+ return false;
88
+ }
81
89
  var rootPos;
82
90
  if (editorExperiment('nested-dnd', true)) {
83
91
  rootPos = view.state.doc.resolve(pos).pos;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.13.8",
3
+ "version": "2.13.9",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
49
- "@atlaskit/primitives": "^13.0.0",
49
+ "@atlaskit/primitives": "^13.1.0",
50
50
  "@atlaskit/theme": "^14.0.0",
51
51
  "@atlaskit/tmp-editor-statsig": "^2.12.0",
52
52
  "@atlaskit/tokens": "^2.2.0",