@atlaskit/editor-plugin-layout 1.12.10 → 1.12.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-layout
2
2
 
3
+ ## 1.12.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#171974](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/171974)
8
+ [`bc888f2b9c449`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bc888f2b9c449) -
9
+ Fire analytics event from BreakoutResizer component when breakout is resized
10
+ - [#171077](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/171077)
11
+ [`0a92cf56671ac`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0a92cf56671ac) -
12
+ ED-25867 always show drag handler for layout columns
13
+ - Updated dependencies
14
+
3
15
  ## 1.12.10
4
16
 
5
17
  ### Patch Changes
@@ -18,6 +18,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
18
18
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
19
19
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
20
20
  var LayoutBreakoutResizer = function LayoutBreakoutResizer(_ref) {
21
+ var _pluginInjectionApi$a;
21
22
  var pluginInjectionApi = _ref.pluginInjectionApi,
22
23
  forwardRef = _ref.forwardRef,
23
24
  getPos = _ref.getPos,
@@ -36,7 +37,8 @@ var LayoutBreakoutResizer = function LayoutBreakoutResizer(_ref) {
36
37
  nodeType: "layoutSection",
37
38
  getEditorWidth: getEditorWidth,
38
39
  disabled: (editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled) === true,
39
- parentRef: parentRef
40
+ parentRef: parentRef,
41
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions
40
42
  });
41
43
  };
42
44
  var toDOM = function toDOM() {
@@ -65,17 +65,17 @@ var getWidthsForPreset = function getWidthsForPreset(presetLayout) {
65
65
  };
66
66
  var isValidLayoutWidthDistributions = function isValidLayoutWidthDistributions(layoutSection) {
67
67
  var totalWidth = 0;
68
+ var hasInvalidWidth = false;
68
69
  (0, _utils.mapChildren)(layoutSection, function (column) {
69
70
  return column.attrs.width;
70
71
  }).forEach(function (width) {
71
72
  if (typeof width === 'number' && isFinite(width) && width > 0 && width <= 100) {
72
73
  totalWidth += width;
74
+ } else {
75
+ hasInvalidWidth = true;
73
76
  }
74
-
75
- // not a valid width, e.g. 0, 100, undefined
76
- return false;
77
77
  });
78
- return Math.round(totalWidth) === 100;
78
+ return !hasInvalidWidth && Math.round(totalWidth) === 100;
79
79
  };
80
80
 
81
81
  /**
@@ -127,7 +127,13 @@ var getPresetLayout = exports.getPresetLayout = function getPresetLayout(section
127
127
  }
128
128
  return;
129
129
  };
130
+ var isLayoutOutOfSync = function isLayoutOutOfSync(node, presetLayout) {
131
+ return node.childCount !== getWidthsForPreset(presetLayout).length;
132
+ };
130
133
  var getSelectedLayout = exports.getSelectedLayout = function getSelectedLayout(maybeLayoutSection, current) {
134
+ if (maybeLayoutSection && isLayoutOutOfSync(maybeLayoutSection, current) && (0, _experiments.editorExperiment)('advanced_layouts', true)) {
135
+ return getDefaultPresetLayout(maybeLayoutSection);
136
+ }
131
137
  if (maybeLayoutSection && getPresetLayout(maybeLayoutSection)) {
132
138
  return getPresetLayout(maybeLayoutSection) || current;
133
139
  }
@@ -13,6 +13,7 @@ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
13
13
  var _state = require("@atlaskit/editor-prosemirror/state");
14
14
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
15
15
  var _view = require("@atlaskit/editor-prosemirror/view");
16
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
16
17
  var _actions = require("./actions");
17
18
  var _pluginKey = require("./plugin-key");
18
19
  var _utils3 = require("./utils");
@@ -66,6 +67,20 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
66
67
  allowSingleColumnLayout: allowSingleColumnLayout
67
68
  };
68
69
  };
70
+
71
+ // To prevent a single-column layout,
72
+ // if a user attempts to delete a layout column and
73
+ // we will force remove the content instead.
74
+ // There are some edge cases where user can delete a layout column
75
+ // see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
76
+ var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
77
+ var sel = state.selection;
78
+ 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)) {
79
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
80
+ return true;
81
+ }
82
+ return false;
83
+ };
69
84
  var _default = exports.default = function _default(options) {
70
85
  return new _safePlugin.SafePlugin({
71
86
  key: _pluginKey.pluginKey,
@@ -94,7 +109,11 @@ var _default = exports.default = function _default(options) {
94
109
  return undefined;
95
110
  },
96
111
  handleKeyDown: (0, _keymap.keydownHandler)({
97
- Tab: (0, _utils.filterCommand)(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn)
112
+ Tab: (0, _utils.filterCommand)(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn),
113
+ 'Mod-Backspace': handleDeleteLayoutColumn,
114
+ 'Mod-Delete': handleDeleteLayoutColumn,
115
+ Backspace: handleDeleteLayoutColumn,
116
+ Delete: handleDeleteLayoutColumn
98
117
  }),
99
118
  handleClickOn: (0, _selection.createSelectionClickHandler)(['layoutColumn'], function (target) {
100
119
  return target.hasAttribute('data-layout-section') || target.hasAttribute('data-layout-column');
@@ -10,6 +10,7 @@ const LayoutBreakoutResizer = ({
10
10
  view,
11
11
  parentRef
12
12
  }) => {
13
+ var _pluginInjectionApi$a;
13
14
  const {
14
15
  editorDisabledState
15
16
  } = useSharedPluginState(pluginInjectionApi, ['editorDisabled']);
@@ -24,7 +25,8 @@ const LayoutBreakoutResizer = ({
24
25
  nodeType: "layoutSection",
25
26
  getEditorWidth: getEditorWidth,
26
27
  disabled: (editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled) === true,
27
- parentRef: parentRef
28
+ parentRef: parentRef,
29
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions
28
30
  });
29
31
  };
30
32
  const toDOM = () => ['div', {
@@ -53,15 +53,15 @@ const getWidthsForPreset = presetLayout => {
53
53
  };
54
54
  const isValidLayoutWidthDistributions = layoutSection => {
55
55
  let totalWidth = 0;
56
+ let hasInvalidWidth = false;
56
57
  mapChildren(layoutSection, column => column.attrs.width).forEach(width => {
57
58
  if (typeof width === 'number' && isFinite(width) && width > 0 && width <= 100) {
58
59
  totalWidth += width;
60
+ } else {
61
+ hasInvalidWidth = true;
59
62
  }
60
-
61
- // not a valid width, e.g. 0, 100, undefined
62
- return false;
63
63
  });
64
- return Math.round(totalWidth) === 100;
64
+ return !hasInvalidWidth && Math.round(totalWidth) === 100;
65
65
  };
66
66
 
67
67
  /**
@@ -111,7 +111,13 @@ export const getPresetLayout = section => {
111
111
  }
112
112
  return;
113
113
  };
114
+ const isLayoutOutOfSync = (node, presetLayout) => {
115
+ return node.childCount !== getWidthsForPreset(presetLayout).length;
116
+ };
114
117
  export const getSelectedLayout = (maybeLayoutSection, current) => {
118
+ if (maybeLayoutSection && isLayoutOutOfSync(maybeLayoutSection, current) && editorExperiment('advanced_layouts', true)) {
119
+ return getDefaultPresetLayout(maybeLayoutSection);
120
+ }
115
121
  if (maybeLayoutSection && getPresetLayout(maybeLayoutSection)) {
116
122
  return getPresetLayout(maybeLayoutSection) || current;
117
123
  }
@@ -2,9 +2,10 @@ 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 { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
6
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
9
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
9
10
  import { pluginKey } from './plugin-key';
10
11
  import { getMaybeLayoutSection } from './utils';
@@ -61,6 +62,20 @@ const getInitialPluginState = (options, state) => {
61
62
  allowSingleColumnLayout
62
63
  };
63
64
  };
65
+
66
+ // To prevent a single-column layout,
67
+ // if a user attempts to delete a layout column and
68
+ // we will force remove the content instead.
69
+ // There are some edge cases where user can delete a layout column
70
+ // see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
71
+ const handleDeleteLayoutColumn = (state, dispatch) => {
72
+ const sel = state.selection;
73
+ 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)) {
74
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
75
+ return true;
76
+ }
77
+ return false;
78
+ };
64
79
  export default (options => new SafePlugin({
65
80
  key: pluginKey,
66
81
  state: {
@@ -87,7 +102,11 @@ export default (options => new SafePlugin({
87
102
  return undefined;
88
103
  },
89
104
  handleKeyDown: keydownHandler({
90
- Tab: filter(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn)
105
+ Tab: filter(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn),
106
+ 'Mod-Backspace': handleDeleteLayoutColumn,
107
+ 'Mod-Delete': handleDeleteLayoutColumn,
108
+ Backspace: handleDeleteLayoutColumn,
109
+ Delete: handleDeleteLayoutColumn
91
110
  }),
92
111
  handleClickOn: createSelectionClickHandler(['layoutColumn'], target => target.hasAttribute('data-layout-section') || target.hasAttribute('data-layout-column'), {
93
112
  useLongPressSelection: options.useLongPressSelection || false,
@@ -11,6 +11,7 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
11
11
  import { BreakoutResizer, ignoreResizerMutations } from '@atlaskit/editor-common/resizer';
12
12
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
13
13
  var LayoutBreakoutResizer = function LayoutBreakoutResizer(_ref) {
14
+ var _pluginInjectionApi$a;
14
15
  var pluginInjectionApi = _ref.pluginInjectionApi,
15
16
  forwardRef = _ref.forwardRef,
16
17
  getPos = _ref.getPos,
@@ -29,7 +30,8 @@ var LayoutBreakoutResizer = function LayoutBreakoutResizer(_ref) {
29
30
  nodeType: "layoutSection",
30
31
  getEditorWidth: getEditorWidth,
31
32
  disabled: (editorDisabledState === null || editorDisabledState === void 0 ? void 0 : editorDisabledState.editorDisabled) === true,
32
- parentRef: parentRef
33
+ parentRef: parentRef,
34
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions
33
35
  });
34
36
  };
35
37
  var toDOM = function toDOM() {
@@ -56,17 +56,17 @@ var getWidthsForPreset = function getWidthsForPreset(presetLayout) {
56
56
  };
57
57
  var isValidLayoutWidthDistributions = function isValidLayoutWidthDistributions(layoutSection) {
58
58
  var totalWidth = 0;
59
+ var hasInvalidWidth = false;
59
60
  mapChildren(layoutSection, function (column) {
60
61
  return column.attrs.width;
61
62
  }).forEach(function (width) {
62
63
  if (typeof width === 'number' && isFinite(width) && width > 0 && width <= 100) {
63
64
  totalWidth += width;
65
+ } else {
66
+ hasInvalidWidth = true;
64
67
  }
65
-
66
- // not a valid width, e.g. 0, 100, undefined
67
- return false;
68
68
  });
69
- return Math.round(totalWidth) === 100;
69
+ return !hasInvalidWidth && Math.round(totalWidth) === 100;
70
70
  };
71
71
 
72
72
  /**
@@ -118,7 +118,13 @@ export var getPresetLayout = function getPresetLayout(section) {
118
118
  }
119
119
  return;
120
120
  };
121
+ var isLayoutOutOfSync = function isLayoutOutOfSync(node, presetLayout) {
122
+ return node.childCount !== getWidthsForPreset(presetLayout).length;
123
+ };
121
124
  export var getSelectedLayout = function getSelectedLayout(maybeLayoutSection, current) {
125
+ if (maybeLayoutSection && isLayoutOutOfSync(maybeLayoutSection, current) && editorExperiment('advanced_layouts', true)) {
126
+ return getDefaultPresetLayout(maybeLayoutSection);
127
+ }
122
128
  if (maybeLayoutSection && getPresetLayout(maybeLayoutSection)) {
123
129
  return getPresetLayout(maybeLayoutSection) || current;
124
130
  }
@@ -5,9 +5,10 @@ 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 { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
9
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
11
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
11
12
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from './actions';
12
13
  import { pluginKey } from './plugin-key';
13
14
  import { getMaybeLayoutSection } from './utils';
@@ -59,6 +60,20 @@ var getInitialPluginState = function getInitialPluginState(options, state) {
59
60
  allowSingleColumnLayout: allowSingleColumnLayout
60
61
  };
61
62
  };
63
+
64
+ // To prevent a single-column layout,
65
+ // if a user attempts to delete a layout column and
66
+ // we will force remove the content instead.
67
+ // There are some edge cases where user can delete a layout column
68
+ // see packages/editor/editor-plugin-layout-tests/src/__tests__/unit/delete.ts
69
+ var handleDeleteLayoutColumn = function handleDeleteLayoutColumn(state, dispatch) {
70
+ var sel = state.selection;
71
+ 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)) {
72
+ dispatch(state.tr.deleteRange(sel.from + 1, sel.from + sel.node.content.size));
73
+ return true;
74
+ }
75
+ return false;
76
+ };
62
77
  export default (function (options) {
63
78
  return new SafePlugin({
64
79
  key: pluginKey,
@@ -87,7 +102,11 @@ export default (function (options) {
87
102
  return undefined;
88
103
  },
89
104
  handleKeyDown: keydownHandler({
90
- Tab: filter(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn)
105
+ Tab: filter(isWholeSelectionInsideLayoutColumn, moveCursorToNextColumn),
106
+ 'Mod-Backspace': handleDeleteLayoutColumn,
107
+ 'Mod-Delete': handleDeleteLayoutColumn,
108
+ Backspace: handleDeleteLayoutColumn,
109
+ Delete: handleDeleteLayoutColumn
91
110
  }),
92
111
  handleClickOn: createSelectionClickHandler(['layoutColumn'], function (target) {
93
112
  return target.hasAttribute('data-layout-section') || target.hasAttribute('data-layout-column');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-layout",
3
- "version": "1.12.10",
3
+ "version": "1.12.11",
4
4
  "description": "Layout plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,9 +38,9 @@
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
39
39
  "@atlaskit/editor-plugin-width": "^1.3.0",
40
40
  "@atlaskit/editor-prosemirror": "6.2.1",
41
- "@atlaskit/icon": "^22.28.0",
41
+ "@atlaskit/icon": "^23.0.0",
42
42
  "@atlaskit/platform-feature-flags": "^0.3.0",
43
- "@atlaskit/tmp-editor-statsig": "^2.21.0",
43
+ "@atlaskit/tmp-editor-statsig": "^2.22.0",
44
44
  "@atlaskit/tokens": "^2.4.0",
45
45
  "@babel/runtime": "^7.0.0",
46
46
  "@emotion/react": "^11.7.1"