@atlaskit/editor-plugin-layout 1.13.0 → 1.14.0

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,23 @@
1
1
  # @atlaskit/editor-plugin-layout
2
2
 
3
+ ## 1.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#109549](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109549)
8
+ [`d6907dac2c08d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d6907dac2c08d) -
9
+ ED-26300 Delete a layout section by delete the 2nd last column from the layout
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 1.13.1
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 1.13.0
4
22
 
5
23
  ### Minor Changes
@@ -260,8 +260,6 @@ var decreaseColumns = function decreaseColumns(node, insideRightEdgePos) {
260
260
  * Switching from 3 -> 2 moves all the content of the third col inside the second before
261
261
  * removing it
262
262
  */
263
- // Ignored via go/ees005
264
- // eslint-disable-next-line @typescript-eslint/max-params
265
263
  function forceColumnStructure(state, node, pos, presetLayout) {
266
264
  var tr = state.tr;
267
265
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -296,9 +294,6 @@ function forceColumnStructure(state, node, pos, presetLayout) {
296
294
  }
297
295
  return tr;
298
296
  }
299
-
300
- // Ignored via go/ees005
301
- // eslint-disable-next-line @typescript-eslint/max-params
302
297
  function forceColumnStructureNew(state, node, pos, presetLayout) {
303
298
  var tr = state.tr;
304
299
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -326,9 +321,6 @@ function columnWidth(node, schema, widths) {
326
321
  }
327
322
  });
328
323
  }
329
-
330
- // Ignored via go/ees005
331
- // eslint-disable-next-line @typescript-eslint/max-params
332
324
  function forceColumnWidths(state, tr, pos, presetLayout) {
333
325
  var node = tr.doc.nodeAt(pos);
334
326
  if (!node) {
@@ -336,9 +328,6 @@ function forceColumnWidths(state, tr, pos, presetLayout) {
336
328
  }
337
329
  return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
338
330
  }
339
-
340
- // Ignored via go/ees005
341
- // eslint-disable-next-line @typescript-eslint/max-params
342
331
  function forceSectionToPresetLayout(state, node, pos, presetLayout) {
343
332
  var forceColumnStructureFn = (0, _experiments.editorExperiment)('advanced_layouts', true) ? forceColumnStructureNew : forceColumnStructure;
344
333
  var tr = forceColumnStructureFn(state, node, pos, presetLayout);
@@ -403,9 +392,12 @@ function layoutNeedChanges(node) {
403
392
  var getDefaultPresetLayout = function getDefaultPresetLayout(layoutNode) {
404
393
  var layoutColumnCount = layoutNode.childCount;
405
394
  if (layoutColumnCount <= 1) {
395
+ if ((0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_dnd_remove_layout')) {
396
+ return 'single';
397
+ }
398
+
406
399
  // This prevents the creation of a single column layout
407
400
  // once we support single column layout, we can return 'single'
408
-
409
401
  return (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
410
402
  }
411
403
  switch (layoutColumnCount) {
@@ -10,11 +10,14 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
10
  var _selection = require("@atlaskit/editor-common/selection");
11
11
  var _utils = require("@atlaskit/editor-common/utils");
12
12
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
13
+ var _model = require("@atlaskit/editor-prosemirror/model");
13
14
  var _state = require("@atlaskit/editor-prosemirror/state");
14
15
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
16
  var _view = require("@atlaskit/editor-prosemirror/view");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
18
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
17
19
  var _actions = require("./actions");
20
+ var _consts = require("./consts");
18
21
  var _pluginKey = require("./plugin-key");
19
22
  var _utils3 = require("./utils");
20
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -80,7 +83,23 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
80
83
  var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
81
84
  var sel = state.selection;
82
85
  if (sel instanceof _state.NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
83
- dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
86
+ if ((0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_dnd_remove_layout')) {
87
+ var _sel$$from$parent$las, _sel$$from$parent$fir;
88
+ var tr = state.tr;
89
+ var layoutContentFragment = sel.$from.parentOffset === 0 ? _model.Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : _model.Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
90
+ var parent = (0, _utils2.findParentNodeClosestToPos)(sel.$from, function (node) {
91
+ return node.type.name === 'layoutSection';
92
+ });
93
+ if (parent) {
94
+ var layoutSectionPos = tr.mapping.map(parent.pos);
95
+ var layoutSectionNodeSize = parent.node.nodeSize;
96
+ dispatch(state.tr.replaceWith(layoutSectionPos, layoutSectionPos + layoutSectionNodeSize, layoutContentFragment));
97
+ return true;
98
+ }
99
+ return false;
100
+ } else {
101
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
102
+ }
84
103
  return true;
85
104
  }
86
105
  return false;
@@ -92,8 +111,6 @@ var _default = exports.default = function _default(options) {
92
111
  init: function init(_, state) {
93
112
  return getInitialPluginState(options, state);
94
113
  },
95
- // Ignored via go/ees005
96
- // eslint-disable-next-line @typescript-eslint/max-params
97
114
  apply: function apply(tr, pluginState, _oldState, newState) {
98
115
  if (tr.docChanged || tr.selectionSet) {
99
116
  var maybeLayoutSection = (0, _utils3.getMaybeLayoutSection)(newState);
@@ -154,19 +171,34 @@ var _default = exports.default = function _default(options) {
154
171
  changes.push(change);
155
172
  }
156
173
  });
174
+ if ((0, _experiments.editorExperiment)('advanced_layouts', true) && changes.length === 1 && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_dnd_remove_layout')) {
175
+ var _change$slice$content, _change$slice$content2;
176
+ var change = changes[0];
177
+ // when need to update a layoutColumn with width 100
178
+ // meaning a single column layout has been create,
179
+ // We replace the layout with its content
180
+ // This is to prevent a single column layout from being created
181
+ // when a user deletes a layoutColumn
182
+ if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === _consts.EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
183
+ var tr = newState.tr;
184
+ var content = change.slice.content.firstChild.content;
185
+ tr.replaceWith(change.from - 1, change.to, content);
186
+ return tr;
187
+ }
188
+ }
157
189
  if (changes.length) {
158
- var tr = newState.tr;
190
+ var _tr = newState.tr;
159
191
  var selection = newState.selection.toJSON();
160
192
  changes.forEach(function (change) {
161
- tr.replaceRange(change.from, change.to, change.slice);
193
+ _tr.replaceRange(change.from, change.to, change.slice);
162
194
  });
163
195
 
164
196
  // selecting and deleting across columns in 3 col layouts can remove
165
197
  // a layoutColumn so we fix the structure here
166
- tr = (0, _actions.fixColumnStructure)(newState) || tr;
167
- if (tr.docChanged) {
168
- tr.setSelection(_state.Selection.fromJSON(tr.doc, selection));
169
- return tr;
198
+ _tr = (0, _actions.fixColumnStructure)(newState) || _tr;
199
+ if (_tr.docChanged) {
200
+ _tr.setSelection(_state.Selection.fromJSON(_tr.doc, selection));
201
+ return _tr;
170
202
  }
171
203
  }
172
204
  return;
@@ -8,10 +8,7 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _nodeviews = require("../nodeviews");
10
10
  var pluginKey = exports.pluginKey = new _state.PluginKey('layoutResizingPlugin');
11
- var _default = exports.default = function _default(options, pluginInjectionApi, portalProviderAPI, eventDispatcher
12
- // Ignored via go/ees005
13
- // eslint-disable-next-line @typescript-eslint/max-params
14
- ) {
11
+ var _default = exports.default = function _default(options, pluginInjectionApi, portalProviderAPI, eventDispatcher) {
15
12
  return new _safePlugin.SafePlugin({
16
13
  key: pluginKey,
17
14
  props: {
@@ -115,10 +115,7 @@ var LAYOUT_WITH_THREE_COL_DISTRIBUTION = [{
115
115
  icon: _LayoutThreeWithLeftSidebars.LayoutThreeWithLeftSidebarsIcon,
116
116
  iconFallback: _LayoutThreeWithLeftSidebars.LayoutThreeWithLeftSidebarsIcon
117
117
  }];
118
- var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI
119
- // Ignored via go/ees005
120
- // eslint-disable-next-line @typescript-eslint/max-params
121
- ) {
118
+ var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI) {
122
119
  return {
123
120
  id: item.id,
124
121
  type: 'button',
@@ -200,10 +197,7 @@ var getAdvancedLayoutItems = function getAdvancedLayoutItems(_ref) {
200
197
  }]
201
198
  }, separator, deleteButton]);
202
199
  };
203
- var buildToolbar = exports.buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api
204
- // Ignored via go/ees005
205
- // eslint-disable-next-line @typescript-eslint/max-params
206
- ) {
200
+ var buildToolbar = exports.buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api) {
207
201
  var _api$decorations$acti, _api$decorations, _api$analytics;
208
202
  var _ref2 = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
209
203
  hoverDecoration = _ref2.hoverDecoration;
@@ -237,8 +237,6 @@ const decreaseColumns = (node, insideRightEdgePos, columnsNumberToRemove = 1) =>
237
237
  * Switching from 3 -> 2 moves all the content of the third col inside the second before
238
238
  * removing it
239
239
  */
240
- // Ignored via go/ees005
241
- // eslint-disable-next-line @typescript-eslint/max-params
242
240
  function forceColumnStructure(state, node, pos, presetLayout) {
243
241
  const tr = state.tr;
244
242
  const insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -273,9 +271,6 @@ function forceColumnStructure(state, node, pos, presetLayout) {
273
271
  }
274
272
  return tr;
275
273
  }
276
-
277
- // Ignored via go/ees005
278
- // eslint-disable-next-line @typescript-eslint/max-params
279
274
  function forceColumnStructureNew(state, node, pos, presetLayout) {
280
275
  const tr = state.tr;
281
276
  const insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -304,9 +299,6 @@ function columnWidth(node, schema, widths) {
304
299
  }
305
300
  });
306
301
  }
307
-
308
- // Ignored via go/ees005
309
- // eslint-disable-next-line @typescript-eslint/max-params
310
302
  function forceColumnWidths(state, tr, pos, presetLayout) {
311
303
  const node = tr.doc.nodeAt(pos);
312
304
  if (!node) {
@@ -314,9 +306,6 @@ function forceColumnWidths(state, tr, pos, presetLayout) {
314
306
  }
315
307
  return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
316
308
  }
317
-
318
- // Ignored via go/ees005
319
- // eslint-disable-next-line @typescript-eslint/max-params
320
309
  export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
321
310
  const forceColumnStructureFn = editorExperiment('advanced_layouts', true) ? forceColumnStructureNew : forceColumnStructure;
322
311
  let tr = forceColumnStructureFn(state, node, pos, presetLayout);
@@ -378,9 +367,12 @@ function layoutNeedChanges(node) {
378
367
  const getDefaultPresetLayout = layoutNode => {
379
368
  const layoutColumnCount = layoutNode.childCount;
380
369
  if (layoutColumnCount <= 1) {
370
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
371
+ return 'single';
372
+ }
373
+
381
374
  // This prevents the creation of a single column layout
382
375
  // once we support single column layout, we can return 'single'
383
-
384
376
  return fg('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
385
377
  }
386
378
  switch (layoutColumnCount) {
@@ -2,11 +2,14 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
3
3
  import { filterCommand as filter } from '@atlaskit/editor-common/utils';
4
4
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
5
6
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
- import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
+ import { findParentNodeClosestToPos, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
8
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
8
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
11
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
12
+ import { EVEN_DISTRIBUTED_COL_WIDTHS } from './consts';
10
13
  import { pluginKey } from './plugin-key';
11
14
  import { getMaybeLayoutSection } from './utils';
12
15
  export const DEFAULT_LAYOUT = 'two_equal';
@@ -75,7 +78,23 @@ const getInitialPluginState = (options, state) => {
75
78
  const handleDeleteLayoutColumn = (state, dispatch) => {
76
79
  const sel = state.selection;
77
80
  if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true)) {
78
- dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
81
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
82
+ var _sel$$from$parent$las, _sel$$from$parent$fir;
83
+ const tr = state.tr;
84
+ const layoutContentFragment = sel.$from.parentOffset === 0 ? Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
85
+ const parent = findParentNodeClosestToPos(sel.$from, node => {
86
+ return node.type.name === 'layoutSection';
87
+ });
88
+ if (parent) {
89
+ const layoutSectionPos = tr.mapping.map(parent.pos);
90
+ const layoutSectionNodeSize = parent.node.nodeSize;
91
+ dispatch(state.tr.replaceWith(layoutSectionPos, layoutSectionPos + layoutSectionNodeSize, layoutContentFragment));
92
+ return true;
93
+ }
94
+ return false;
95
+ } else {
96
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
97
+ }
79
98
  return true;
80
99
  }
81
100
  return false;
@@ -84,8 +103,6 @@ export default (options => new SafePlugin({
84
103
  key: pluginKey,
85
104
  state: {
86
105
  init: (_, state) => getInitialPluginState(options, state),
87
- // Ignored via go/ees005
88
- // eslint-disable-next-line @typescript-eslint/max-params
89
106
  apply: (tr, pluginState, _oldState, newState) => {
90
107
  if (tr.docChanged || tr.selectionSet) {
91
108
  const maybeLayoutSection = getMaybeLayoutSection(newState);
@@ -143,6 +160,23 @@ export default (options => new SafePlugin({
143
160
  changes.push(change);
144
161
  }
145
162
  });
163
+ if (editorExperiment('advanced_layouts', true) && changes.length === 1 && fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
164
+ var _change$slice$content, _change$slice$content2;
165
+ const change = changes[0];
166
+ // when need to update a layoutColumn with width 100
167
+ // meaning a single column layout has been create,
168
+ // We replace the layout with its content
169
+ // This is to prevent a single column layout from being created
170
+ // when a user deletes a layoutColumn
171
+ if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
172
+ const tr = newState.tr;
173
+ const {
174
+ content
175
+ } = change.slice.content.firstChild;
176
+ tr.replaceWith(change.from - 1, change.to, content);
177
+ return tr;
178
+ }
179
+ }
146
180
  if (changes.length) {
147
181
  let tr = newState.tr;
148
182
  const selection = newState.selection.toJSON();
@@ -2,10 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { LayoutSectionView } from '../nodeviews';
4
4
  export const pluginKey = new PluginKey('layoutResizingPlugin');
5
- export default ((options, pluginInjectionApi, portalProviderAPI, eventDispatcher
6
- // Ignored via go/ees005
7
- // eslint-disable-next-line @typescript-eslint/max-params
8
- ) => new SafePlugin({
5
+ export default ((options, pluginInjectionApi, portalProviderAPI, eventDispatcher) => new SafePlugin({
9
6
  key: pluginKey,
10
7
  props: {
11
8
  nodeViews: {
@@ -104,10 +104,7 @@ const LAYOUT_WITH_THREE_COL_DISTRIBUTION = [{
104
104
  icon: LayoutThreeWithLeftSidebarsIcon,
105
105
  iconFallback: LayoutThreeWithLeftSidebarsIcon
106
106
  }];
107
- const buildLayoutButton = (intl, item, currentLayout, editorAnalyticsAPI
108
- // Ignored via go/ees005
109
- // eslint-disable-next-line @typescript-eslint/max-params
110
- ) => ({
107
+ const buildLayoutButton = (intl, item, currentLayout, editorAnalyticsAPI) => ({
111
108
  id: item.id,
112
109
  type: 'button',
113
110
  icon: item.icon,
@@ -186,10 +183,7 @@ const getAdvancedLayoutItems = ({
186
183
  }]
187
184
  }, separator, deleteButton];
188
185
  };
189
- export const buildToolbar = (state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api
190
- // Ignored via go/ees005
191
- // eslint-disable-next-line @typescript-eslint/max-params
192
- ) => {
186
+ export const buildToolbar = (state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api) => {
193
187
  var _api$decorations$acti, _api$decorations, _api$analytics;
194
188
  const {
195
189
  hoverDecoration
@@ -251,8 +251,6 @@ var decreaseColumns = function decreaseColumns(node, insideRightEdgePos) {
251
251
  * Switching from 3 -> 2 moves all the content of the third col inside the second before
252
252
  * removing it
253
253
  */
254
- // Ignored via go/ees005
255
- // eslint-disable-next-line @typescript-eslint/max-params
256
254
  function forceColumnStructure(state, node, pos, presetLayout) {
257
255
  var tr = state.tr;
258
256
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -287,9 +285,6 @@ function forceColumnStructure(state, node, pos, presetLayout) {
287
285
  }
288
286
  return tr;
289
287
  }
290
-
291
- // Ignored via go/ees005
292
- // eslint-disable-next-line @typescript-eslint/max-params
293
288
  function forceColumnStructureNew(state, node, pos, presetLayout) {
294
289
  var tr = state.tr;
295
290
  var insideRightEdgeOfLayoutSection = pos + node.nodeSize - 1;
@@ -317,9 +312,6 @@ function columnWidth(node, schema, widths) {
317
312
  }
318
313
  });
319
314
  }
320
-
321
- // Ignored via go/ees005
322
- // eslint-disable-next-line @typescript-eslint/max-params
323
315
  function forceColumnWidths(state, tr, pos, presetLayout) {
324
316
  var node = tr.doc.nodeAt(pos);
325
317
  if (!node) {
@@ -327,9 +319,6 @@ function forceColumnWidths(state, tr, pos, presetLayout) {
327
319
  }
328
320
  return tr.replaceWith(pos + 1, pos + node.nodeSize - 1, columnWidth(node, state.schema, getWidthsForPreset(presetLayout)));
329
321
  }
330
-
331
- // Ignored via go/ees005
332
- // eslint-disable-next-line @typescript-eslint/max-params
333
322
  export function forceSectionToPresetLayout(state, node, pos, presetLayout) {
334
323
  var forceColumnStructureFn = editorExperiment('advanced_layouts', true) ? forceColumnStructureNew : forceColumnStructure;
335
324
  var tr = forceColumnStructureFn(state, node, pos, presetLayout);
@@ -394,9 +383,12 @@ function layoutNeedChanges(node) {
394
383
  var getDefaultPresetLayout = function getDefaultPresetLayout(layoutNode) {
395
384
  var layoutColumnCount = layoutNode.childCount;
396
385
  if (layoutColumnCount <= 1) {
386
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
387
+ return 'single';
388
+ }
389
+
397
390
  // This prevents the creation of a single column layout
398
391
  // once we support single column layout, we can return 'single'
399
-
400
392
  return fg('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
401
393
  }
402
394
  switch (layoutColumnCount) {
@@ -5,11 +5,14 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { createSelectionClickHandler } from '@atlaskit/editor-common/selection';
6
6
  import { filterCommand as filter } from '@atlaskit/editor-common/utils';
7
7
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
8
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
8
9
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
- import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
+ import { findParentNodeClosestToPos, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
11
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
11
13
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
14
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
15
+ import { EVEN_DISTRIBUTED_COL_WIDTHS } from './consts';
13
16
  import { pluginKey } from './plugin-key';
14
17
  import { getMaybeLayoutSection } from './utils';
15
18
  export var DEFAULT_LAYOUT = 'two_equal';
@@ -73,7 +76,23 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
73
76
  var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
74
77
  var sel = state.selection;
75
78
  if (sel instanceof NodeSelection && sel.node.type.name === 'layoutColumn' && sel.$from.parent.type.name === 'layoutSection' && sel.$from.parent.childCount === 2 && dispatch && editorExperiment('advanced_layouts', true)) {
76
- dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
79
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
80
+ var _sel$$from$parent$las, _sel$$from$parent$fir;
81
+ var tr = state.tr;
82
+ var layoutContentFragment = sel.$from.parentOffset === 0 ? Fragment.from((_sel$$from$parent$las = sel.$from.parent.lastChild) === null || _sel$$from$parent$las === void 0 ? void 0 : _sel$$from$parent$las.content) : Fragment.from((_sel$$from$parent$fir = sel.$from.parent.firstChild) === null || _sel$$from$parent$fir === void 0 ? void 0 : _sel$$from$parent$fir.content);
83
+ var parent = findParentNodeClosestToPos(sel.$from, function (node) {
84
+ return node.type.name === 'layoutSection';
85
+ });
86
+ if (parent) {
87
+ var layoutSectionPos = tr.mapping.map(parent.pos);
88
+ var layoutSectionNodeSize = parent.node.nodeSize;
89
+ dispatch(state.tr.replaceWith(layoutSectionPos, layoutSectionPos + layoutSectionNodeSize, layoutContentFragment));
90
+ return true;
91
+ }
92
+ return false;
93
+ } else {
94
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
95
+ }
77
96
  return true;
78
97
  }
79
98
  return false;
@@ -85,8 +104,6 @@ export default (function (options) {
85
104
  init: function init(_, state) {
86
105
  return getInitialPluginState(options, state);
87
106
  },
88
- // Ignored via go/ees005
89
- // eslint-disable-next-line @typescript-eslint/max-params
90
107
  apply: function apply(tr, pluginState, _oldState, newState) {
91
108
  if (tr.docChanged || tr.selectionSet) {
92
109
  var maybeLayoutSection = getMaybeLayoutSection(newState);
@@ -147,19 +164,34 @@ export default (function (options) {
147
164
  changes.push(change);
148
165
  }
149
166
  });
167
+ if (editorExperiment('advanced_layouts', true) && changes.length === 1 && fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
168
+ var _change$slice$content, _change$slice$content2;
169
+ var change = changes[0];
170
+ // when need to update a layoutColumn with width 100
171
+ // meaning a single column layout has been create,
172
+ // We replace the layout with its content
173
+ // This is to prevent a single column layout from being created
174
+ // when a user deletes a layoutColumn
175
+ if (change.slice.content.childCount === 1 && ((_change$slice$content = change.slice.content.firstChild) === null || _change$slice$content === void 0 ? void 0 : _change$slice$content.type.name) === 'layoutColumn' && ((_change$slice$content2 = change.slice.content.firstChild) === null || _change$slice$content2 === void 0 ? void 0 : _change$slice$content2.attrs.width) === EVEN_DISTRIBUTED_COL_WIDTHS[1]) {
176
+ var tr = newState.tr;
177
+ var content = change.slice.content.firstChild.content;
178
+ tr.replaceWith(change.from - 1, change.to, content);
179
+ return tr;
180
+ }
181
+ }
150
182
  if (changes.length) {
151
- var tr = newState.tr;
183
+ var _tr = newState.tr;
152
184
  var selection = newState.selection.toJSON();
153
185
  changes.forEach(function (change) {
154
- tr.replaceRange(change.from, change.to, change.slice);
186
+ _tr.replaceRange(change.from, change.to, change.slice);
155
187
  });
156
188
 
157
189
  // selecting and deleting across columns in 3 col layouts can remove
158
190
  // a layoutColumn so we fix the structure here
159
- tr = fixColumnStructure(newState) || tr;
160
- if (tr.docChanged) {
161
- tr.setSelection(Selection.fromJSON(tr.doc, selection));
162
- return tr;
191
+ _tr = fixColumnStructure(newState) || _tr;
192
+ if (_tr.docChanged) {
193
+ _tr.setSelection(Selection.fromJSON(_tr.doc, selection));
194
+ return _tr;
163
195
  }
164
196
  }
165
197
  return;
@@ -2,10 +2,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { LayoutSectionView } from '../nodeviews';
4
4
  export var pluginKey = new PluginKey('layoutResizingPlugin');
5
- export default (function (options, pluginInjectionApi, portalProviderAPI, eventDispatcher
6
- // Ignored via go/ees005
7
- // eslint-disable-next-line @typescript-eslint/max-params
8
- ) {
5
+ export default (function (options, pluginInjectionApi, portalProviderAPI, eventDispatcher) {
9
6
  return new SafePlugin({
10
7
  key: pluginKey,
11
8
  props: {
@@ -105,10 +105,7 @@ var LAYOUT_WITH_THREE_COL_DISTRIBUTION = [{
105
105
  icon: LayoutThreeWithLeftSidebarsIcon,
106
106
  iconFallback: LayoutThreeWithLeftSidebarsIcon
107
107
  }];
108
- var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI
109
- // Ignored via go/ees005
110
- // eslint-disable-next-line @typescript-eslint/max-params
111
- ) {
108
+ var buildLayoutButton = function buildLayoutButton(intl, item, currentLayout, editorAnalyticsAPI) {
112
109
  return {
113
110
  id: item.id,
114
111
  type: 'button',
@@ -190,10 +187,7 @@ var getAdvancedLayoutItems = function getAdvancedLayoutItems(_ref) {
190
187
  }]
191
188
  }, separator, deleteButton]);
192
189
  };
193
- export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api
194
- // Ignored via go/ees005
195
- // eslint-disable-next-line @typescript-eslint/max-params
196
- ) {
190
+ export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout, addSidebarLayouts, allowSingleColumnLayout, api) {
197
191
  var _api$decorations$acti, _api$decorations, _api$analytics;
198
192
  var _ref2 = (_api$decorations$acti = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions) !== null && _api$decorations$acti !== void 0 ? _api$decorations$acti : {},
199
193
  hoverDecoration = _ref2.hoverDecoration;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { type EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
3
  import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
4
4
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
@@ -35,7 +35,7 @@ export declare class LayoutSectionView extends ReactNodeView<LayoutSectionViewPr
35
35
  contentDOM: HTMLElement | undefined;
36
36
  };
37
37
  setDomAttrs(node: PMNode, element: HTMLElement): void;
38
- render(props: LayoutSectionViewProps, forwardRef: ForwardRef): JSX.Element;
38
+ render(props: LayoutSectionViewProps, forwardRef: ForwardRef): React.JSX.Element;
39
39
  ignoreMutation(mutation: MutationRecord | {
40
40
  type: 'selection';
41
41
  target: Element;
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { type EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
3
  import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
4
4
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
@@ -35,7 +35,7 @@ export declare class LayoutSectionView extends ReactNodeView<LayoutSectionViewPr
35
35
  contentDOM: HTMLElement | undefined;
36
36
  };
37
37
  setDomAttrs(node: PMNode, element: HTMLElement): void;
38
- render(props: LayoutSectionViewProps, forwardRef: ForwardRef): JSX.Element;
38
+ render(props: LayoutSectionViewProps, forwardRef: ForwardRef): React.JSX.Element;
39
39
  ignoreMutation(mutation: MutationRecord | {
40
40
  type: 'selection';
41
41
  target: Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-layout",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Layout plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,17 +32,17 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^46.1.0",
35
- "@atlaskit/editor-common": "^99.1.0",
36
- "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
- "@atlaskit/editor-plugin-decorations": "^1.3.0",
38
- "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
35
+ "@atlaskit/editor-common": "^99.9.0",
36
+ "@atlaskit/editor-plugin-analytics": "^1.11.0",
37
+ "@atlaskit/editor-plugin-decorations": "^1.4.0",
38
+ "@atlaskit/editor-plugin-editor-disabled": "^1.4.0",
39
39
  "@atlaskit/editor-plugin-selection": "^1.6.0",
40
40
  "@atlaskit/editor-plugin-width": "^2.0.0",
41
41
  "@atlaskit/editor-prosemirror": "6.2.1",
42
- "@atlaskit/icon": "^23.3.0",
43
- "@atlaskit/platform-feature-flags": "^0.3.0",
44
- "@atlaskit/tmp-editor-statsig": "^2.34.0",
45
- "@atlaskit/tokens": "^3.0.0",
42
+ "@atlaskit/icon": "^23.7.0",
43
+ "@atlaskit/platform-feature-flags": "^1.0.0",
44
+ "@atlaskit/tmp-editor-statsig": "^2.43.0",
45
+ "@atlaskit/tokens": "^3.3.0",
46
46
  "@babel/runtime": "^7.0.0",
47
47
  "@emotion/react": "^11.7.1"
48
48
  },
@@ -106,6 +106,9 @@
106
106
  },
107
107
  "platform_editor_advanced_layouts_post_fix_patch_3": {
108
108
  "type": "boolean"
109
+ },
110
+ "platform_editor_advanced_layouts_dnd_remove_layout": {
111
+ "type": "boolean"
109
112
  }
110
113
  }
111
114
  }