@atlaskit/editor-plugin-block-controls 3.8.7 → 3.8.8

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-controls
2
2
 
3
+ ## 3.8.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#138622](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/138622)
8
+ [`09f425c925d38`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/09f425c925d38) -
9
+ Add support for quick insert in cell selection
10
+
3
11
  ## 3.8.7
4
12
 
5
13
  ### Patch Changes
@@ -84,17 +84,13 @@ function transformSourceSlice(nodeCopy, destType) {
84
84
  }
85
85
  return nodeCopy;
86
86
  }
87
- var isDragLayoutColumnToTopLevel = function isDragLayoutColumnToTopLevel($from, $to) {
87
+ var nodesSupportDragLayoutColumnInto = ['tableCell', 'tableHeader', 'panel', 'expand', 'nestedExpand'];
88
+ var isDragLayoutColumnIntoSupportedNodes = function isDragLayoutColumnIntoSupportedNodes($from, $to) {
88
89
  var _$from$nodeAfter;
89
- return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.depth === 0;
90
- };
91
- var isDragLayoutColumnIntoTable = function isDragLayoutColumnIntoTable($from, $to) {
92
- var _$from$nodeAfter2;
93
- return ((_$from$nodeAfter2 = $from.nodeAfter) === null || _$from$nodeAfter2 === void 0 ? void 0 : _$from$nodeAfter2.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && ($to.parent.type.name === 'tableCell' || $to.parent.type.name === 'tableHeader');
94
- };
95
- var isDragLayoutColumnIntoPanel = function isDragLayoutColumnIntoPanel($from, $to) {
96
- var _$from$nodeAfter3;
97
- return ((_$from$nodeAfter3 = $from.nodeAfter) === null || _$from$nodeAfter3 === void 0 ? void 0 : _$from$nodeAfter3.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.parent.type.name === 'panel';
90
+ var isTopLevel = $to.depth === 0;
91
+ var isDragIntoNodes = nodesSupportDragLayoutColumnInto.includes($to.parent.type.name);
92
+ var supportedCondition = (0, _platformFeatureFlags.fg)('platform_editor_drag_layout_column_into_nodes') ? isDragIntoNodes || isTopLevel : isTopLevel;
93
+ return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && supportedCondition;
98
94
  };
99
95
 
100
96
  /**
@@ -383,19 +379,15 @@ var moveNode = exports.moveNode = function moveNode(api) {
383
379
  var destType = $to.node().type;
384
380
  var destParent = $to.node($to.depth);
385
381
  var sourceNode = $handlePos.nodeAfter;
386
- var dragLayoutColumnToTopLevel = isDragLayoutColumnToTopLevel($handlePos, $to);
387
- var dragLayoutColumnIntoTable = isDragLayoutColumnIntoTable($handlePos, $to);
388
- var dragLayoutColumnIntoPanel = isDragLayoutColumnIntoPanel($handlePos, $to);
389
382
 
390
383
  //TODO: ED-26959 - Does this need to be updated with new selection logic above? ^
391
- // Move a layout column to top level
392
- // Move a layout column into a table cell, only moves the content into the cell
393
- // Move a layout column into a panel, only moves the content into the panel
394
- if (sourceNode && (dragLayoutColumnToTopLevel || dragLayoutColumnIntoTable || dragLayoutColumnIntoPanel)) {
384
+ // Move a layout column to top level, or table cell, or panel, or expand, only moves the content into them
385
+ if (sourceNode && isDragLayoutColumnIntoSupportedNodes($handlePos, $to)) {
395
386
  // need update after we support single column layout.
396
387
  var layoutColumnContent = sourceNode.content;
397
388
  var fragment;
398
- if (dragLayoutColumnIntoTable) {
389
+ // if drop into table, and layout column contains expand, transform it to nestedExpand
390
+ if (['tableCell', 'tableHeader'].includes($to.parent.type.name)) {
399
391
  var contentContainsExpand = (0, _utils2.findChildrenByType)(sourceNode, expand).length > 0;
400
392
  fragment = contentContainsExpand ? (0, _validation.transformFragmentExpandToNestedExpand)(_model.Fragment.from(layoutColumnContent)) : _model.Fragment.from(layoutColumnContent);
401
393
  if (!fragment) {
@@ -10,7 +10,6 @@ var _transform = require("@atlaskit/editor-prosemirror/transform");
10
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
11
  var firstNodeDecPluginKey = exports.firstNodeDecPluginKey = new _state.PluginKey('firstNodeDec');
12
12
  var createFirstNodeDecSet = function createFirstNodeDecSet(state) {
13
- ;
14
13
  var firstNode = state.doc.firstChild;
15
14
  if (!firstNode) {
16
15
  return _view.DecorationSet.empty;
@@ -90,8 +90,8 @@ var memoizedTransformExpandToNestedExpand = exports.memoizedTransformExpandToNes
90
90
  });
91
91
  var canCreateNodeWithContentInsideAnotherNode = exports.canCreateNodeWithContentInsideAnotherNode = function canCreateNodeWithContentInsideAnotherNode(nodeTypesToCreate, nodeWithTargetFragment) {
92
92
  try {
93
- return !!nodeTypesToCreate.every(function (nodeType) {
94
- return nodeType.createChecked({}, nodeWithTargetFragment);
93
+ return !!nodeTypesToCreate.every(function (nodeTypeToCreate) {
94
+ return nodeTypeToCreate.createChecked({}, nodeWithTargetFragment);
95
95
  });
96
96
  } catch (e) {
97
97
  return false;
@@ -100,24 +100,29 @@ var canCreateNodeWithContentInsideAnotherNode = exports.canCreateNodeWithContent
100
100
  function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNodePos, destNode) {
101
101
  var srcNodeType = srcNode.type;
102
102
  var schema = srcNodeType.schema;
103
- var destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
104
- var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;
103
+ var _schema$nodes = schema.nodes,
104
+ table = _schema$nodes.table,
105
+ tableCell = _schema$nodes.tableCell,
106
+ tableHeader = _schema$nodes.tableHeader,
107
+ expand = _schema$nodes.expand,
108
+ nestedExpand = _schema$nodes.nestedExpand,
109
+ doc = _schema$nodes.doc,
110
+ panel = _schema$nodes.panel,
111
+ layoutColumn = _schema$nodes.layoutColumn,
112
+ layoutSection = _schema$nodes.layoutSection;
113
+ var destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type;
114
+ var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type;
105
115
  var layoutColumnContent = srcNode.content;
106
116
  var isNestingTablesSupported = (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes') && (0, _experiments.editorExperiment)('nested-tables-in-tables', true, {
107
117
  exposure: true
108
118
  });
109
- var tableNodeType = schema.nodes.table;
110
- if (activeNodeType === 'layoutColumn' && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
119
+ if (activeNodeType === layoutColumn && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
111
120
  // Allow drag layout column and drop into layout section
112
- if ((destNode === null || destNode === void 0 ? void 0 : destNode.type.name) === 'layoutSection' || destParentNodeType === 'doc') {
121
+ if ((destNode === null || destNode === void 0 ? void 0 : destNode.type) === layoutSection || destParentNodeType === doc) {
113
122
  return true;
114
123
  }
115
124
  if ((0, _platformFeatureFlags.fg)('platform_editor_drag_layout_column_into_nodes')) {
116
- if (destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') {
117
- var _schema$nodes = schema.nodes,
118
- tableCell = _schema$nodes.tableCell,
119
- tableHeader = _schema$nodes.tableHeader,
120
- expand = _schema$nodes.expand;
125
+ if (destParentNodeType === tableCell || destParentNodeType === tableHeader) {
121
126
  var contentContainsExpand = (0, _utils.findChildrenByType)(srcNode, expand).length > 0;
122
127
  //convert expand to nestedExpand if there are expands inside the layout column
123
128
  // otherwise, the createChecked will fail as expand is not a valid child of tableCell/tableHeader, but nestedExpand is
@@ -127,36 +132,41 @@ function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNodePos,
127
132
  }
128
133
  return canCreateNodeWithContentInsideAnotherNode([tableCell, tableHeader], convertedFragment);
129
134
  }
130
- if (destParentNodeType === 'panel') {
131
- var panel = schema.nodes.panel;
135
+ if (destParentNodeType === panel) {
132
136
  return canCreateNodeWithContentInsideAnotherNode([panel], layoutColumnContent);
133
137
  }
138
+ if (destParentNodeType === expand) {
139
+ return canCreateNodeWithContentInsideAnotherNode([expand], layoutColumnContent);
140
+ }
141
+ if (destParentNodeType === nestedExpand) {
142
+ return canCreateNodeWithContentInsideAnotherNode([nestedExpand], layoutColumnContent);
143
+ }
134
144
  }
135
145
  }
136
146
 
137
147
  // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
138
148
  if ((0, _experiments.editorExperiment)('nested-expand-in-expand', false)) {
139
- if (destParentNodeType === 'expand' && (activeNodeType === 'expand' || activeNodeType === 'nestedExpand')) {
149
+ if (destParentNodeType === expand && (activeNodeType === expand || activeNodeType === nestedExpand)) {
140
150
  return false;
141
151
  }
142
152
  }
143
153
 
144
154
  // NOTE: this will block drop targets from showing for dragging a table into another table
145
155
  // unless nested tables are supported and the nesting depth does not exceed 1
146
- if ((destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') && activeNodeType === 'table') {
147
- var nestingDepth = (0, _nesting.getParentOfTypeCount)(tableNodeType)($destNodePos);
156
+ if ((destParentNodeType === tableCell || destParentNodeType === tableHeader) && activeNodeType === table) {
157
+ var nestingDepth = (0, _nesting.getParentOfTypeCount)(table)($destNodePos);
148
158
  if (!isNestingTablesSupported || isNestingTablesSupported && nestingDepth > 1) {
149
159
  return false;
150
160
  }
151
161
  }
152
162
  if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
153
163
  if (memoizedTransformExpandToNestedExpand(srcNode)) {
154
- srcNodeType = schema.nodes.nestedExpand;
164
+ srcNodeType = nestedExpand;
155
165
  } else {
156
166
  return false;
157
167
  }
158
168
  } else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
159
- srcNodeType = schema.nodes.expand;
169
+ srcNodeType = expand;
160
170
  }
161
171
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
162
172
  }
@@ -15,6 +15,7 @@ var _messages = require("@atlaskit/editor-common/messages");
15
15
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
16
16
  var _state = require("@atlaskit/editor-prosemirror/state");
17
17
  var _utils = require("@atlaskit/editor-prosemirror/utils");
18
+ var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
18
19
  var _add = _interopRequireDefault(require("@atlaskit/icon/utility/add"));
19
20
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _primitives = require("@atlaskit/primitives");
@@ -206,10 +207,11 @@ var TypeAheadControl = exports.TypeAheadControl = function TypeAheadControl(_ref
206
207
  if (start !== undefined) {
207
208
  // if the selection is not within the node this decoration is rendered at
208
209
  // or the node is non-editable, then insert a newline and trigger quick insert
209
- if (!(0, _documentChecks.isSelectionInNode)(start, view) || (0, _documentChecks.isNonEditableBlock)(start, view)) {
210
+ var isSelectionInsideNode = (0, _documentChecks.isSelectionInNode)(start, view);
211
+ if (!isSelectionInsideNode || (0, _documentChecks.isNonEditableBlock)(start, view)) {
210
212
  api.core.actions.execute((0, _editorCommands.createNewLine)(start));
211
213
  }
212
- if ((0, _documentChecks.isSelectionInNode)(start, view)) {
214
+ if (isSelectionInsideNode) {
213
215
  // text or element with be deselected and the / added immediately after the paragraph
214
216
  // unless the selection is empty
215
217
  var currentSelection = view.state.selection;
@@ -246,6 +248,24 @@ var TypeAheadControl = exports.TypeAheadControl = function TypeAheadControl(_ref
246
248
  });
247
249
  }
248
250
  }
251
+ if (currentSelection instanceof _cellSelection.CellSelection && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_4')) {
252
+ // find the last inline position in the selection
253
+ var lastInlinePosition = _state.TextSelection.near(view.state.selection.$to, -1);
254
+ lastInlinePosition && api.core.actions.execute(function (_ref4) {
255
+ var tr = _ref4.tr;
256
+ if (!(lastInlinePosition instanceof _state.TextSelection)) {
257
+ // this will create a new line after the node
258
+ (0, _editorCommands.createNewLine)(lastInlinePosition.from)({
259
+ tr: tr
260
+ });
261
+ // this will find the next valid text position after the node
262
+ tr.setSelection(_state.TextSelection.create(tr.doc, lastInlinePosition.to));
263
+ } else {
264
+ tr.setSelection(lastInlinePosition);
265
+ }
266
+ return tr;
267
+ });
268
+ }
249
269
  }
250
270
  }
251
271
  (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl', true);
@@ -293,16 +313,16 @@ var TypeAheadControl = exports.TypeAheadControl = function TypeAheadControl(_ref
293
313
  xcss: [tooltipContainerStyles]
294
314
  }, tooltipPressable()) : tooltipPressable());
295
315
  };
296
- var QuickInsertWithVisibility = exports.QuickInsertWithVisibility = function QuickInsertWithVisibility(_ref4) {
297
- var view = _ref4.view,
298
- api = _ref4.api,
299
- formatMessage = _ref4.formatMessage,
300
- getPos = _ref4.getPos,
301
- nodeType = _ref4.nodeType,
302
- anchorName = _ref4.anchorName,
303
- rootAnchorName = _ref4.rootAnchorName,
304
- rootNodeType = _ref4.rootNodeType,
305
- anchorRectCache = _ref4.anchorRectCache;
316
+ var QuickInsertWithVisibility = exports.QuickInsertWithVisibility = function QuickInsertWithVisibility(_ref5) {
317
+ var view = _ref5.view,
318
+ api = _ref5.api,
319
+ formatMessage = _ref5.formatMessage,
320
+ getPos = _ref5.getPos,
321
+ nodeType = _ref5.nodeType,
322
+ anchorName = _ref5.anchorName,
323
+ rootAnchorName = _ref5.rootAnchorName,
324
+ rootNodeType = _ref5.rootNodeType,
325
+ anchorRectCache = _ref5.anchorRectCache;
306
326
  return /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
307
327
  api: api
308
328
  }, /*#__PURE__*/_react.default.createElement(TypeAheadControl, {
@@ -77,17 +77,13 @@ function transformSourceSlice(nodeCopy, destType) {
77
77
  }
78
78
  return nodeCopy;
79
79
  }
80
- const isDragLayoutColumnToTopLevel = ($from, $to) => {
80
+ const nodesSupportDragLayoutColumnInto = ['tableCell', 'tableHeader', 'panel', 'expand', 'nestedExpand'];
81
+ const isDragLayoutColumnIntoSupportedNodes = ($from, $to) => {
81
82
  var _$from$nodeAfter;
82
- return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.depth === 0;
83
- };
84
- const isDragLayoutColumnIntoTable = ($from, $to) => {
85
- var _$from$nodeAfter2;
86
- return ((_$from$nodeAfter2 = $from.nodeAfter) === null || _$from$nodeAfter2 === void 0 ? void 0 : _$from$nodeAfter2.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && ($to.parent.type.name === 'tableCell' || $to.parent.type.name === 'tableHeader');
87
- };
88
- const isDragLayoutColumnIntoPanel = ($from, $to) => {
89
- var _$from$nodeAfter3;
90
- return ((_$from$nodeAfter3 = $from.nodeAfter) === null || _$from$nodeAfter3 === void 0 ? void 0 : _$from$nodeAfter3.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.parent.type.name === 'panel';
83
+ const isTopLevel = $to.depth === 0;
84
+ const isDragIntoNodes = nodesSupportDragLayoutColumnInto.includes($to.parent.type.name);
85
+ const supportedCondition = fg('platform_editor_drag_layout_column_into_nodes') ? isDragIntoNodes || isTopLevel : isTopLevel;
86
+ return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && supportedCondition;
91
87
  };
92
88
 
93
89
  /**
@@ -386,19 +382,15 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
386
382
  const destType = $to.node().type;
387
383
  const destParent = $to.node($to.depth);
388
384
  const sourceNode = $handlePos.nodeAfter;
389
- const dragLayoutColumnToTopLevel = isDragLayoutColumnToTopLevel($handlePos, $to);
390
- const dragLayoutColumnIntoTable = isDragLayoutColumnIntoTable($handlePos, $to);
391
- const dragLayoutColumnIntoPanel = isDragLayoutColumnIntoPanel($handlePos, $to);
392
385
 
393
386
  //TODO: ED-26959 - Does this need to be updated with new selection logic above? ^
394
- // Move a layout column to top level
395
- // Move a layout column into a table cell, only moves the content into the cell
396
- // Move a layout column into a panel, only moves the content into the panel
397
- if (sourceNode && (dragLayoutColumnToTopLevel || dragLayoutColumnIntoTable || dragLayoutColumnIntoPanel)) {
387
+ // Move a layout column to top level, or table cell, or panel, or expand, only moves the content into them
388
+ if (sourceNode && isDragLayoutColumnIntoSupportedNodes($handlePos, $to)) {
398
389
  // need update after we support single column layout.
399
390
  const layoutColumnContent = sourceNode.content;
400
391
  let fragment;
401
- if (dragLayoutColumnIntoTable) {
392
+ // if drop into table, and layout column contains expand, transform it to nestedExpand
393
+ if (['tableCell', 'tableHeader'].includes($to.parent.type.name)) {
402
394
  const contentContainsExpand = findChildrenByType(sourceNode, expand).length > 0;
403
395
  fragment = contentContainsExpand ? transformFragmentExpandToNestedExpand(Fragment.from(layoutColumnContent)) : Fragment.from(layoutColumnContent);
404
396
  if (!fragment) {
@@ -4,7 +4,6 @@ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/tra
4
4
  import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
5
5
  export const firstNodeDecPluginKey = new PluginKey('firstNodeDec');
6
6
  const createFirstNodeDecSet = state => {
7
- ;
8
7
  const firstNode = state.doc.firstChild;
9
8
  if (!firstNode) {
10
9
  return DecorationSet.empty;
@@ -82,7 +82,7 @@ export const memoizedTransformExpandToNestedExpand = memoizeOne(node => {
82
82
  });
83
83
  export const canCreateNodeWithContentInsideAnotherNode = (nodeTypesToCreate, nodeWithTargetFragment) => {
84
84
  try {
85
- return !!nodeTypesToCreate.every(nodeType => nodeType.createChecked({}, nodeWithTargetFragment));
85
+ return !!nodeTypesToCreate.every(nodeTypeToCreate => nodeTypeToCreate.createChecked({}, nodeWithTargetFragment));
86
86
  } catch (e) {
87
87
  return false;
88
88
  }
@@ -90,25 +90,30 @@ export const canCreateNodeWithContentInsideAnotherNode = (nodeTypesToCreate, nod
90
90
  export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNodePos, destNode) {
91
91
  let srcNodeType = srcNode.type;
92
92
  const schema = srcNodeType.schema;
93
- const destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
94
- const activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;
93
+ const {
94
+ table,
95
+ tableCell,
96
+ tableHeader,
97
+ expand,
98
+ nestedExpand,
99
+ doc,
100
+ panel,
101
+ layoutColumn,
102
+ layoutSection
103
+ } = schema.nodes;
104
+ const destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type;
105
+ const activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type;
95
106
  const layoutColumnContent = srcNode.content;
96
107
  const isNestingTablesSupported = fg('platform_editor_use_nested_table_pm_nodes') && editorExperiment('nested-tables-in-tables', true, {
97
108
  exposure: true
98
109
  });
99
- const tableNodeType = schema.nodes.table;
100
- if (activeNodeType === 'layoutColumn' && editorExperiment('advanced_layouts', true)) {
110
+ if (activeNodeType === layoutColumn && editorExperiment('advanced_layouts', true)) {
101
111
  // Allow drag layout column and drop into layout section
102
- if ((destNode === null || destNode === void 0 ? void 0 : destNode.type.name) === 'layoutSection' || destParentNodeType === 'doc') {
112
+ if ((destNode === null || destNode === void 0 ? void 0 : destNode.type) === layoutSection || destParentNodeType === doc) {
103
113
  return true;
104
114
  }
105
115
  if (fg('platform_editor_drag_layout_column_into_nodes')) {
106
- if (destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') {
107
- const {
108
- tableCell,
109
- tableHeader,
110
- expand
111
- } = schema.nodes;
116
+ if (destParentNodeType === tableCell || destParentNodeType === tableHeader) {
112
117
  const contentContainsExpand = findChildrenByType(srcNode, expand).length > 0;
113
118
  //convert expand to nestedExpand if there are expands inside the layout column
114
119
  // otherwise, the createChecked will fail as expand is not a valid child of tableCell/tableHeader, but nestedExpand is
@@ -118,38 +123,41 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNo
118
123
  }
119
124
  return canCreateNodeWithContentInsideAnotherNode([tableCell, tableHeader], convertedFragment);
120
125
  }
121
- if (destParentNodeType === 'panel') {
122
- const {
123
- panel
124
- } = schema.nodes;
126
+ if (destParentNodeType === panel) {
125
127
  return canCreateNodeWithContentInsideAnotherNode([panel], layoutColumnContent);
126
128
  }
129
+ if (destParentNodeType === expand) {
130
+ return canCreateNodeWithContentInsideAnotherNode([expand], layoutColumnContent);
131
+ }
132
+ if (destParentNodeType === nestedExpand) {
133
+ return canCreateNodeWithContentInsideAnotherNode([nestedExpand], layoutColumnContent);
134
+ }
127
135
  }
128
136
  }
129
137
 
130
138
  // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
131
139
  if (editorExperiment('nested-expand-in-expand', false)) {
132
- if (destParentNodeType === 'expand' && (activeNodeType === 'expand' || activeNodeType === 'nestedExpand')) {
140
+ if (destParentNodeType === expand && (activeNodeType === expand || activeNodeType === nestedExpand)) {
133
141
  return false;
134
142
  }
135
143
  }
136
144
 
137
145
  // NOTE: this will block drop targets from showing for dragging a table into another table
138
146
  // unless nested tables are supported and the nesting depth does not exceed 1
139
- if ((destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') && activeNodeType === 'table') {
140
- const nestingDepth = getParentOfTypeCount(tableNodeType)($destNodePos);
147
+ if ((destParentNodeType === tableCell || destParentNodeType === tableHeader) && activeNodeType === table) {
148
+ const nestingDepth = getParentOfTypeCount(table)($destNodePos);
141
149
  if (!isNestingTablesSupported || isNestingTablesSupported && nestingDepth > 1) {
142
150
  return false;
143
151
  }
144
152
  }
145
153
  if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
146
154
  if (memoizedTransformExpandToNestedExpand(srcNode)) {
147
- srcNodeType = schema.nodes.nestedExpand;
155
+ srcNodeType = nestedExpand;
148
156
  } else {
149
157
  return false;
150
158
  }
151
159
  } else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
152
- srcNodeType = schema.nodes.expand;
160
+ srcNodeType = expand;
153
161
  }
154
162
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
155
163
  }
@@ -5,6 +5,7 @@ import { blockControlsMessages as messages } from '@atlaskit/editor-common/messa
5
5
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
6
6
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
7
  import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
8
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
8
9
  import AddIcon from '@atlaskit/icon/utility/add';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
10
11
  import { Box, Pressable, xcss } from '@atlaskit/primitives';
@@ -192,10 +193,11 @@ export const TypeAheadControl = ({
192
193
  if (start !== undefined) {
193
194
  // if the selection is not within the node this decoration is rendered at
194
195
  // or the node is non-editable, then insert a newline and trigger quick insert
195
- if (!isSelectionInNode(start, view) || isNonEditableBlock(start, view)) {
196
+ const isSelectionInsideNode = isSelectionInNode(start, view);
197
+ if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
196
198
  api.core.actions.execute(createNewLine(start));
197
199
  }
198
- if (isSelectionInNode(start, view)) {
200
+ if (isSelectionInsideNode) {
199
201
  // text or element with be deselected and the / added immediately after the paragraph
200
202
  // unless the selection is empty
201
203
  const currentSelection = view.state.selection;
@@ -232,6 +234,25 @@ export const TypeAheadControl = ({
232
234
  });
233
235
  }
234
236
  }
237
+ if (currentSelection instanceof CellSelection && fg('platform_editor_controls_patch_4')) {
238
+ // find the last inline position in the selection
239
+ const lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
240
+ lastInlinePosition && api.core.actions.execute(({
241
+ tr
242
+ }) => {
243
+ if (!(lastInlinePosition instanceof TextSelection)) {
244
+ // this will create a new line after the node
245
+ createNewLine(lastInlinePosition.from)({
246
+ tr
247
+ });
248
+ // this will find the next valid text position after the node
249
+ tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
250
+ } else {
251
+ tr.setSelection(lastInlinePosition);
252
+ }
253
+ return tr;
254
+ });
255
+ }
235
256
  }
236
257
  }
237
258
  (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.actions.openTypeAhead('blockControl', true);
@@ -78,17 +78,13 @@ function transformSourceSlice(nodeCopy, destType) {
78
78
  }
79
79
  return nodeCopy;
80
80
  }
81
- var isDragLayoutColumnToTopLevel = function isDragLayoutColumnToTopLevel($from, $to) {
81
+ var nodesSupportDragLayoutColumnInto = ['tableCell', 'tableHeader', 'panel', 'expand', 'nestedExpand'];
82
+ var isDragLayoutColumnIntoSupportedNodes = function isDragLayoutColumnIntoSupportedNodes($from, $to) {
82
83
  var _$from$nodeAfter;
83
- return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.depth === 0;
84
- };
85
- var isDragLayoutColumnIntoTable = function isDragLayoutColumnIntoTable($from, $to) {
86
- var _$from$nodeAfter2;
87
- return ((_$from$nodeAfter2 = $from.nodeAfter) === null || _$from$nodeAfter2 === void 0 ? void 0 : _$from$nodeAfter2.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && ($to.parent.type.name === 'tableCell' || $to.parent.type.name === 'tableHeader');
88
- };
89
- var isDragLayoutColumnIntoPanel = function isDragLayoutColumnIntoPanel($from, $to) {
90
- var _$from$nodeAfter3;
91
- return ((_$from$nodeAfter3 = $from.nodeAfter) === null || _$from$nodeAfter3 === void 0 ? void 0 : _$from$nodeAfter3.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && $to.parent.type.name === 'panel';
84
+ var isTopLevel = $to.depth === 0;
85
+ var isDragIntoNodes = nodesSupportDragLayoutColumnInto.includes($to.parent.type.name);
86
+ var supportedCondition = fg('platform_editor_drag_layout_column_into_nodes') ? isDragIntoNodes || isTopLevel : isTopLevel;
87
+ return ((_$from$nodeAfter = $from.nodeAfter) === null || _$from$nodeAfter === void 0 ? void 0 : _$from$nodeAfter.type.name) === 'layoutColumn' && $from.parent.type.name === 'layoutSection' && supportedCondition;
92
88
  };
93
89
 
94
90
  /**
@@ -377,19 +373,15 @@ export var moveNode = function moveNode(api) {
377
373
  var destType = $to.node().type;
378
374
  var destParent = $to.node($to.depth);
379
375
  var sourceNode = $handlePos.nodeAfter;
380
- var dragLayoutColumnToTopLevel = isDragLayoutColumnToTopLevel($handlePos, $to);
381
- var dragLayoutColumnIntoTable = isDragLayoutColumnIntoTable($handlePos, $to);
382
- var dragLayoutColumnIntoPanel = isDragLayoutColumnIntoPanel($handlePos, $to);
383
376
 
384
377
  //TODO: ED-26959 - Does this need to be updated with new selection logic above? ^
385
- // Move a layout column to top level
386
- // Move a layout column into a table cell, only moves the content into the cell
387
- // Move a layout column into a panel, only moves the content into the panel
388
- if (sourceNode && (dragLayoutColumnToTopLevel || dragLayoutColumnIntoTable || dragLayoutColumnIntoPanel)) {
378
+ // Move a layout column to top level, or table cell, or panel, or expand, only moves the content into them
379
+ if (sourceNode && isDragLayoutColumnIntoSupportedNodes($handlePos, $to)) {
389
380
  // need update after we support single column layout.
390
381
  var layoutColumnContent = sourceNode.content;
391
382
  var fragment;
392
- if (dragLayoutColumnIntoTable) {
383
+ // if drop into table, and layout column contains expand, transform it to nestedExpand
384
+ if (['tableCell', 'tableHeader'].includes($to.parent.type.name)) {
393
385
  var contentContainsExpand = findChildrenByType(sourceNode, expand).length > 0;
394
386
  fragment = contentContainsExpand ? transformFragmentExpandToNestedExpand(Fragment.from(layoutColumnContent)) : Fragment.from(layoutColumnContent);
395
387
  if (!fragment) {
@@ -4,7 +4,6 @@ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/tra
4
4
  import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
5
5
  export var firstNodeDecPluginKey = new PluginKey('firstNodeDec');
6
6
  var createFirstNodeDecSet = function createFirstNodeDecSet(state) {
7
- ;
8
7
  var firstNode = state.doc.firstChild;
9
8
  if (!firstNode) {
10
9
  return DecorationSet.empty;
@@ -80,8 +80,8 @@ export var memoizedTransformExpandToNestedExpand = memoizeOne(function (node) {
80
80
  });
81
81
  export var canCreateNodeWithContentInsideAnotherNode = function canCreateNodeWithContentInsideAnotherNode(nodeTypesToCreate, nodeWithTargetFragment) {
82
82
  try {
83
- return !!nodeTypesToCreate.every(function (nodeType) {
84
- return nodeType.createChecked({}, nodeWithTargetFragment);
83
+ return !!nodeTypesToCreate.every(function (nodeTypeToCreate) {
84
+ return nodeTypeToCreate.createChecked({}, nodeWithTargetFragment);
85
85
  });
86
86
  } catch (e) {
87
87
  return false;
@@ -90,24 +90,29 @@ export var canCreateNodeWithContentInsideAnotherNode = function canCreateNodeWit
90
90
  export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNodePos, destNode) {
91
91
  var srcNodeType = srcNode.type;
92
92
  var schema = srcNodeType.schema;
93
- var destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type.name;
94
- var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type.name;
93
+ var _schema$nodes = schema.nodes,
94
+ table = _schema$nodes.table,
95
+ tableCell = _schema$nodes.tableCell,
96
+ tableHeader = _schema$nodes.tableHeader,
97
+ expand = _schema$nodes.expand,
98
+ nestedExpand = _schema$nodes.nestedExpand,
99
+ doc = _schema$nodes.doc,
100
+ panel = _schema$nodes.panel,
101
+ layoutColumn = _schema$nodes.layoutColumn,
102
+ layoutSection = _schema$nodes.layoutSection;
103
+ var destParentNodeType = destParent === null || destParent === void 0 ? void 0 : destParent.type;
104
+ var activeNodeType = srcNode === null || srcNode === void 0 ? void 0 : srcNode.type;
95
105
  var layoutColumnContent = srcNode.content;
96
106
  var isNestingTablesSupported = fg('platform_editor_use_nested_table_pm_nodes') && editorExperiment('nested-tables-in-tables', true, {
97
107
  exposure: true
98
108
  });
99
- var tableNodeType = schema.nodes.table;
100
- if (activeNodeType === 'layoutColumn' && editorExperiment('advanced_layouts', true)) {
109
+ if (activeNodeType === layoutColumn && editorExperiment('advanced_layouts', true)) {
101
110
  // Allow drag layout column and drop into layout section
102
- if ((destNode === null || destNode === void 0 ? void 0 : destNode.type.name) === 'layoutSection' || destParentNodeType === 'doc') {
111
+ if ((destNode === null || destNode === void 0 ? void 0 : destNode.type) === layoutSection || destParentNodeType === doc) {
103
112
  return true;
104
113
  }
105
114
  if (fg('platform_editor_drag_layout_column_into_nodes')) {
106
- if (destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') {
107
- var _schema$nodes = schema.nodes,
108
- tableCell = _schema$nodes.tableCell,
109
- tableHeader = _schema$nodes.tableHeader,
110
- expand = _schema$nodes.expand;
115
+ if (destParentNodeType === tableCell || destParentNodeType === tableHeader) {
111
116
  var contentContainsExpand = findChildrenByType(srcNode, expand).length > 0;
112
117
  //convert expand to nestedExpand if there are expands inside the layout column
113
118
  // otherwise, the createChecked will fail as expand is not a valid child of tableCell/tableHeader, but nestedExpand is
@@ -117,36 +122,41 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNo
117
122
  }
118
123
  return canCreateNodeWithContentInsideAnotherNode([tableCell, tableHeader], convertedFragment);
119
124
  }
120
- if (destParentNodeType === 'panel') {
121
- var panel = schema.nodes.panel;
125
+ if (destParentNodeType === panel) {
122
126
  return canCreateNodeWithContentInsideAnotherNode([panel], layoutColumnContent);
123
127
  }
128
+ if (destParentNodeType === expand) {
129
+ return canCreateNodeWithContentInsideAnotherNode([expand], layoutColumnContent);
130
+ }
131
+ if (destParentNodeType === nestedExpand) {
132
+ return canCreateNodeWithContentInsideAnotherNode([nestedExpand], layoutColumnContent);
133
+ }
124
134
  }
125
135
  }
126
136
 
127
137
  // Place experiments here instead of just inside move-node.ts as it stops the drag marker from appearing.
128
138
  if (editorExperiment('nested-expand-in-expand', false)) {
129
- if (destParentNodeType === 'expand' && (activeNodeType === 'expand' || activeNodeType === 'nestedExpand')) {
139
+ if (destParentNodeType === expand && (activeNodeType === expand || activeNodeType === nestedExpand)) {
130
140
  return false;
131
141
  }
132
142
  }
133
143
 
134
144
  // NOTE: this will block drop targets from showing for dragging a table into another table
135
145
  // unless nested tables are supported and the nesting depth does not exceed 1
136
- if ((destParentNodeType === 'tableCell' || destParentNodeType === 'tableHeader') && activeNodeType === 'table') {
137
- var nestingDepth = getParentOfTypeCount(tableNodeType)($destNodePos);
146
+ if ((destParentNodeType === tableCell || destParentNodeType === tableHeader) && activeNodeType === table) {
147
+ var nestingDepth = getParentOfTypeCount(table)($destNodePos);
138
148
  if (!isNestingTablesSupported || isNestingTablesSupported && nestingDepth > 1) {
139
149
  return false;
140
150
  }
141
151
  }
142
152
  if (isInsideTable(destParent.type) && isExpand(srcNodeType)) {
143
153
  if (memoizedTransformExpandToNestedExpand(srcNode)) {
144
- srcNodeType = schema.nodes.nestedExpand;
154
+ srcNodeType = nestedExpand;
145
155
  } else {
146
156
  return false;
147
157
  }
148
158
  } else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
149
- srcNodeType = schema.nodes.expand;
159
+ srcNodeType = expand;
150
160
  }
151
161
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
152
162
  }
@@ -9,6 +9,7 @@ import { blockControlsMessages as messages } from '@atlaskit/editor-common/messa
9
9
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
10
10
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
11
11
  import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
12
+ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
12
13
  import AddIcon from '@atlaskit/icon/utility/add';
13
14
  import { fg } from '@atlaskit/platform-feature-flags';
14
15
  import { Box, Pressable, xcss } from '@atlaskit/primitives';
@@ -196,10 +197,11 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
196
197
  if (start !== undefined) {
197
198
  // if the selection is not within the node this decoration is rendered at
198
199
  // or the node is non-editable, then insert a newline and trigger quick insert
199
- if (!isSelectionInNode(start, view) || isNonEditableBlock(start, view)) {
200
+ var isSelectionInsideNode = isSelectionInNode(start, view);
201
+ if (!isSelectionInsideNode || isNonEditableBlock(start, view)) {
200
202
  api.core.actions.execute(createNewLine(start));
201
203
  }
202
- if (isSelectionInNode(start, view)) {
204
+ if (isSelectionInsideNode) {
203
205
  // text or element with be deselected and the / added immediately after the paragraph
204
206
  // unless the selection is empty
205
207
  var currentSelection = view.state.selection;
@@ -236,6 +238,24 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
236
238
  });
237
239
  }
238
240
  }
241
+ if (currentSelection instanceof CellSelection && fg('platform_editor_controls_patch_4')) {
242
+ // find the last inline position in the selection
243
+ var lastInlinePosition = TextSelection.near(view.state.selection.$to, -1);
244
+ lastInlinePosition && api.core.actions.execute(function (_ref4) {
245
+ var tr = _ref4.tr;
246
+ if (!(lastInlinePosition instanceof TextSelection)) {
247
+ // this will create a new line after the node
248
+ createNewLine(lastInlinePosition.from)({
249
+ tr: tr
250
+ });
251
+ // this will find the next valid text position after the node
252
+ tr.setSelection(TextSelection.create(tr.doc, lastInlinePosition.to));
253
+ } else {
254
+ tr.setSelection(lastInlinePosition);
255
+ }
256
+ return tr;
257
+ });
258
+ }
239
259
  }
240
260
  }
241
261
  (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl', true);
@@ -283,16 +303,16 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
283
303
  xcss: [tooltipContainerStyles]
284
304
  }, tooltipPressable()) : tooltipPressable());
285
305
  };
286
- export var QuickInsertWithVisibility = function QuickInsertWithVisibility(_ref4) {
287
- var view = _ref4.view,
288
- api = _ref4.api,
289
- formatMessage = _ref4.formatMessage,
290
- getPos = _ref4.getPos,
291
- nodeType = _ref4.nodeType,
292
- anchorName = _ref4.anchorName,
293
- rootAnchorName = _ref4.rootAnchorName,
294
- rootNodeType = _ref4.rootNodeType,
295
- anchorRectCache = _ref4.anchorRectCache;
306
+ export var QuickInsertWithVisibility = function QuickInsertWithVisibility(_ref5) {
307
+ var view = _ref5.view,
308
+ api = _ref5.api,
309
+ formatMessage = _ref5.formatMessage,
310
+ getPos = _ref5.getPos,
311
+ nodeType = _ref5.nodeType,
312
+ anchorName = _ref5.anchorName,
313
+ rootAnchorName = _ref5.rootAnchorName,
314
+ rootNodeType = _ref5.rootNodeType,
315
+ anchorRectCache = _ref5.anchorRectCache;
296
316
  return /*#__PURE__*/React.createElement(VisibilityContainer, {
297
317
  api: api
298
318
  }, /*#__PURE__*/React.createElement(TypeAheadControl, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.8.7",
3
+ "version": "3.8.8",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^47.6.0",
36
- "@atlaskit/editor-common": "^103.1.0",
36
+ "@atlaskit/editor-common": "^103.3.0",
37
37
  "@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
39
39
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
@@ -176,6 +176,9 @@
176
176
  },
177
177
  "platform_editor_controls_widget_visibility": {
178
178
  "type": "boolean"
179
+ },
180
+ "platform_editor_controls_patch_4": {
181
+ "type": "boolean"
179
182
  }
180
183
  }
181
184
  }