@atlaskit/editor-plugin-layout 1.13.1 → 1.15.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,29 @@
1
1
  # @atlaskit/editor-plugin-layout
2
2
 
3
+ ## 1.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#105322](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/105322)
8
+ [`8876083532adc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8876083532adc) -
9
+ Bumped editor-prosemirror version to 7.0.0
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 1.14.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#109549](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109549)
20
+ [`d6907dac2c08d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d6907dac2c08d) -
21
+ ED-26300 Delete a layout section by delete the 2nd last column from the layout
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+
3
27
  ## 1.13.1
4
28
 
5
29
  ### Patch Changes
@@ -392,9 +392,12 @@ function layoutNeedChanges(node) {
392
392
  var getDefaultPresetLayout = function getDefaultPresetLayout(layoutNode) {
393
393
  var layoutColumnCount = layoutNode.childCount;
394
394
  if (layoutColumnCount <= 1) {
395
+ if ((0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_dnd_remove_layout')) {
396
+ return 'single';
397
+ }
398
+
395
399
  // This prevents the creation of a single column layout
396
400
  // once we support single column layout, we can return 'single'
397
-
398
401
  return (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
399
402
  }
400
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;
@@ -152,19 +171,34 @@ var _default = exports.default = function _default(options) {
152
171
  changes.push(change);
153
172
  }
154
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
+ }
155
189
  if (changes.length) {
156
- var tr = newState.tr;
190
+ var _tr = newState.tr;
157
191
  var selection = newState.selection.toJSON();
158
192
  changes.forEach(function (change) {
159
- tr.replaceRange(change.from, change.to, change.slice);
193
+ _tr.replaceRange(change.from, change.to, change.slice);
160
194
  });
161
195
 
162
196
  // selecting and deleting across columns in 3 col layouts can remove
163
197
  // a layoutColumn so we fix the structure here
164
- tr = (0, _actions.fixColumnStructure)(newState) || tr;
165
- if (tr.docChanged) {
166
- tr.setSelection(_state.Selection.fromJSON(tr.doc, selection));
167
- 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;
168
202
  }
169
203
  }
170
204
  return;
@@ -367,9 +367,12 @@ function layoutNeedChanges(node) {
367
367
  const getDefaultPresetLayout = layoutNode => {
368
368
  const layoutColumnCount = layoutNode.childCount;
369
369
  if (layoutColumnCount <= 1) {
370
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
371
+ return 'single';
372
+ }
373
+
370
374
  // This prevents the creation of a single column layout
371
375
  // once we support single column layout, we can return 'single'
372
-
373
376
  return fg('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
374
377
  }
375
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;
@@ -141,6 +160,23 @@ export default (options => new SafePlugin({
141
160
  changes.push(change);
142
161
  }
143
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
+ }
144
180
  if (changes.length) {
145
181
  let tr = newState.tr;
146
182
  const selection = newState.selection.toJSON();
@@ -383,9 +383,12 @@ function layoutNeedChanges(node) {
383
383
  var getDefaultPresetLayout = function getDefaultPresetLayout(layoutNode) {
384
384
  var layoutColumnCount = layoutNode.childCount;
385
385
  if (layoutColumnCount <= 1) {
386
+ if (fg('platform_editor_advanced_layouts_dnd_remove_layout')) {
387
+ return 'single';
388
+ }
389
+
386
390
  // This prevents the creation of a single column layout
387
391
  // once we support single column layout, we can return 'single'
388
-
389
392
  return fg('platform_editor_advanced_layouts_post_fix_patch_1') ? 'two_equal' : 'single';
390
393
  }
391
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;
@@ -145,19 +164,34 @@ export default (function (options) {
145
164
  changes.push(change);
146
165
  }
147
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
+ }
148
182
  if (changes.length) {
149
- var tr = newState.tr;
183
+ var _tr = newState.tr;
150
184
  var selection = newState.selection.toJSON();
151
185
  changes.forEach(function (change) {
152
- tr.replaceRange(change.from, change.to, change.slice);
186
+ _tr.replaceRange(change.from, change.to, change.slice);
153
187
  });
154
188
 
155
189
  // selecting and deleting across columns in 3 col layouts can remove
156
190
  // a layoutColumn so we fix the structure here
157
- tr = fixColumnStructure(newState) || tr;
158
- if (tr.docChanged) {
159
- tr.setSelection(Selection.fromJSON(tr.doc, selection));
160
- return tr;
191
+ _tr = fixColumnStructure(newState) || _tr;
192
+ if (_tr.docChanged) {
193
+ _tr.setSelection(Selection.fromJSON(_tr.doc, selection));
194
+ return _tr;
161
195
  }
162
196
  }
163
197
  return;
@@ -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,10 +35,10 @@ 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
- target: Element;
41
+ target: Node;
42
42
  }): boolean;
43
43
  }
44
44
  export {};
@@ -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,10 +35,10 @@ 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
- target: Element;
41
+ target: Node;
42
42
  }): boolean;
43
43
  }
44
44
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-layout",
3
- "version": "1.13.1",
3
+ "version": "1.15.0",
4
4
  "description": "Layout plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,16 +32,16 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^46.1.0",
35
- "@atlaskit/editor-common": "^99.7.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
- "@atlaskit/editor-plugin-selection": "^1.6.0",
40
- "@atlaskit/editor-plugin-width": "^2.0.0",
41
- "@atlaskit/editor-prosemirror": "6.2.1",
42
- "@atlaskit/icon": "^23.6.0",
35
+ "@atlaskit/editor-common": "^99.10.0",
36
+ "@atlaskit/editor-plugin-analytics": "^1.12.0",
37
+ "@atlaskit/editor-plugin-decorations": "^1.5.0",
38
+ "@atlaskit/editor-plugin-editor-disabled": "^1.5.0",
39
+ "@atlaskit/editor-plugin-selection": "^1.7.0",
40
+ "@atlaskit/editor-plugin-width": "^2.1.0",
41
+ "@atlaskit/editor-prosemirror": "7.0.0",
42
+ "@atlaskit/icon": "^23.7.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.0.0",
44
- "@atlaskit/tmp-editor-statsig": "^2.41.0",
44
+ "@atlaskit/tmp-editor-statsig": "^2.43.0",
45
45
  "@atlaskit/tokens": "^3.3.0",
46
46
  "@babel/runtime": "^7.0.0",
47
47
  "@emotion/react": "^11.7.1"
@@ -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
  }