@atlaskit/editor-plugin-layout 1.12.2 → 1.12.3

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,16 @@
1
1
  # @atlaskit/editor-plugin-layout
2
2
 
3
+ ## 1.12.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#165840](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165840)
8
+ [`02a637ba38316`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/02a637ba38316) -
9
+ [ux] Update layout drop target using anchor position to work in stack layout
10
+ - [#166078](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/166078)
11
+ [`73109f934d566`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/73109f934d566) -
12
+ [ux] [ED-25773] Hide layout floating toolbar when layout column is selected
13
+
3
14
  ## 1.12.2
4
15
 
5
16
  ### Patch Changes
@@ -62,6 +62,14 @@ var getWidthsForPreset = function getWidthsForPreset(presetLayout) {
62
62
  }
63
63
  return [];
64
64
  };
65
+ var isValidLayoutWidthDistributions = function isValidLayoutWidthDistributions(layoutSection) {
66
+ var totalWidth = (0, _utils.mapChildren)(layoutSection, function (column) {
67
+ return column.attrs.width;
68
+ }).reduce(function (total, width) {
69
+ return total + width;
70
+ }, 0);
71
+ return Math.round(totalWidth) === 100;
72
+ };
65
73
 
66
74
  /**
67
75
  * Finds layout preset based on the width attrs of all the layoutColumn nodes
@@ -370,6 +378,9 @@ var setPresetLayout = exports.setPresetLayout = function setPresetLayout(editorA
370
378
  };
371
379
  };
372
380
  function layoutNeedChanges(node) {
381
+ if ((0, _preRelease.isPreRelease2)()) {
382
+ return !getPresetLayout(node) || !isValidLayoutWidthDistributions(node);
383
+ }
373
384
  return !getPresetLayout(node);
374
385
  }
375
386
  function getLayoutChange(node, pos, schema) {
@@ -397,6 +408,7 @@ var fixColumnSizes = exports.fixColumnSizes = function fixColumnSizes(changedTr,
397
408
  if (node.type !== layoutSection) {
398
409
  return true; // Check all internal nodes expect for layout section
399
410
  }
411
+
400
412
  // Node is a section
401
413
  if (layoutNeedChanges(node)) {
402
414
  change = getLayoutChange(node, pos, state.schema);
@@ -14,6 +14,7 @@ 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
16
  var _actions = require("../actions");
17
+ var _utils3 = require("../utils");
17
18
  var _pluginKey = require("./plugin-key");
18
19
  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; }
19
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -51,7 +52,7 @@ var getNodeDecoration = function getNodeDecoration(pos, node) {
51
52
  })];
52
53
  };
53
54
  var getInitialPluginState = function getInitialPluginState(options, state) {
54
- var maybeLayoutSection = (0, _utils2.findParentNodeOfType)(state.schema.nodes.layoutSection)(state.selection);
55
+ var maybeLayoutSection = (0, _utils3.getMaybeLayoutSection)(state);
55
56
  var allowBreakout = options.allowBreakout || false;
56
57
  var addSidebarLayouts = options.UNSAFE_addSidebarLayouts || false;
57
58
  var allowSingleColumnLayout = options.UNSAFE_allowSingleColumnLayout || false;
@@ -74,9 +75,7 @@ var _default = exports.default = function _default(options) {
74
75
  },
75
76
  apply: function apply(tr, pluginState, _oldState, newState) {
76
77
  if (tr.docChanged || tr.selectionSet) {
77
- var layoutSection = newState.schema.nodes.layoutSection,
78
- selection = newState.selection;
79
- var maybeLayoutSection = (0, _utils2.findParentNodeOfType)(layoutSection)(selection) || (0, _utils2.findSelectedNodeOfType)([layoutSection])(selection);
78
+ var maybeLayoutSection = (0, _utils3.getMaybeLayoutSection)(newState);
80
79
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
81
80
  pos: maybeLayoutSection ? maybeLayoutSection.pos : null,
82
81
  selectedLayout: (0, _actions.getSelectedLayout)(maybeLayoutSection && maybeLayoutSection.node, pluginState.selectedLayout)
@@ -182,7 +182,7 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(state, intl, pos
182
182
  onClick: (0, _actions.setPresetLayout)(editorAnalyticsAPI)('five_equal', intl.formatMessage),
183
183
  selected: numberOfColumns === 5
184
184
  }];
185
- var sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns];
185
+ var sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns] || [];
186
186
  return {
187
187
  title: layoutToolbarTitle,
188
188
  getDomRef: function getDomRef(view) {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMaybeLayoutSection = void 0;
7
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
9
+ var getMaybeLayoutSection = exports.getMaybeLayoutSection = function getMaybeLayoutSection(state) {
10
+ var _state$schema$nodes = state.schema.nodes,
11
+ layoutSection = _state$schema$nodes.layoutSection,
12
+ layoutColumn = _state$schema$nodes.layoutColumn,
13
+ selection = state.selection;
14
+ var isLayoutColumn = (0, _experiments.editorExperiment)('advanced_layouts', true) && (0, _utils.findSelectedNodeOfType)([layoutColumn])(selection);
15
+
16
+ // When selection is on layoutColumn, we want to hide floating toolbar, hence don't return layoutSection node here
17
+ return isLayoutColumn ? undefined : (0, _utils.findParentNodeOfType)(layoutSection)(selection) || (0, _utils.findSelectedNodeOfType)([layoutSection])(selection);
18
+ };
@@ -50,6 +50,12 @@ const getWidthsForPreset = presetLayout => {
50
50
  }
51
51
  return [];
52
52
  };
53
+ const isValidLayoutWidthDistributions = layoutSection => {
54
+ const totalWidth = mapChildren(layoutSection, column => column.attrs.width).reduce((total, width) => {
55
+ return total + width;
56
+ }, 0);
57
+ return Math.round(totalWidth) === 100;
58
+ };
53
59
 
54
60
  /**
55
61
  * Finds layout preset based on the width attrs of all the layoutColumn nodes
@@ -348,6 +354,9 @@ export const setPresetLayout = editorAnalyticsAPI => (layout, formatMessage) =>
348
354
  return false;
349
355
  };
350
356
  function layoutNeedChanges(node) {
357
+ if (isPreRelease2()) {
358
+ return !getPresetLayout(node) || !isValidLayoutWidthDistributions(node);
359
+ }
351
360
  return !getPresetLayout(node);
352
361
  }
353
362
  function getLayoutChange(node, pos, schema) {
@@ -377,6 +386,7 @@ export const fixColumnSizes = (changedTr, state) => {
377
386
  if (node.type !== layoutSection) {
378
387
  return true; // Check all internal nodes expect for layout section
379
388
  }
389
+
380
390
  // Node is a section
381
391
  if (layoutNeedChanges(node)) {
382
392
  change = getLayoutChange(node, pos, state.schema);
@@ -3,9 +3,10 @@ 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
5
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
- import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from '../actions';
9
+ import { getMaybeLayoutSection } from '../utils';
9
10
  import { pluginKey } from './plugin-key';
10
11
  export const DEFAULT_LAYOUT = 'two_equal';
11
12
  const isWholeSelectionInsideLayoutColumn = state => {
@@ -46,7 +47,7 @@ const getNodeDecoration = (pos, node) => [Decoration.node(pos, pos + node.nodeSi
46
47
  class: 'selected'
47
48
  })];
48
49
  const getInitialPluginState = (options, state) => {
49
- const maybeLayoutSection = findParentNodeOfType(state.schema.nodes.layoutSection)(state.selection);
50
+ const maybeLayoutSection = getMaybeLayoutSection(state);
50
51
  const allowBreakout = options.allowBreakout || false;
51
52
  const addSidebarLayouts = options.UNSAFE_addSidebarLayouts || false;
52
53
  const allowSingleColumnLayout = options.UNSAFE_allowSingleColumnLayout || false;
@@ -66,15 +67,7 @@ export default (options => new SafePlugin({
66
67
  init: (_, state) => getInitialPluginState(options, state),
67
68
  apply: (tr, pluginState, _oldState, newState) => {
68
69
  if (tr.docChanged || tr.selectionSet) {
69
- const {
70
- schema: {
71
- nodes: {
72
- layoutSection
73
- }
74
- },
75
- selection
76
- } = newState;
77
- const maybeLayoutSection = findParentNodeOfType(layoutSection)(selection) || findSelectedNodeOfType([layoutSection])(selection);
70
+ const maybeLayoutSection = getMaybeLayoutSection(newState);
78
71
  const newPluginState = {
79
72
  ...pluginState,
80
73
  pos: maybeLayoutSection ? maybeLayoutSection.pos : null,
@@ -170,7 +170,7 @@ export const buildToolbar = (state, intl, pos, _allowBreakout, addSidebarLayouts
170
170
  onClick: setPresetLayout(editorAnalyticsAPI)('five_equal', intl.formatMessage),
171
171
  selected: numberOfColumns === 5
172
172
  }];
173
- const sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns];
173
+ const sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns] || [];
174
174
  return {
175
175
  title: layoutToolbarTitle,
176
176
  getDomRef: view => findDomRefAtPos(pos, view.domAtPos.bind(view)),
@@ -0,0 +1,17 @@
1
+ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+ export const getMaybeLayoutSection = state => {
4
+ const {
5
+ schema: {
6
+ nodes: {
7
+ layoutSection,
8
+ layoutColumn
9
+ }
10
+ },
11
+ selection
12
+ } = state;
13
+ const isLayoutColumn = editorExperiment('advanced_layouts', true) && findSelectedNodeOfType([layoutColumn])(selection);
14
+
15
+ // When selection is on layoutColumn, we want to hide floating toolbar, hence don't return layoutSection node here
16
+ return isLayoutColumn ? undefined : findParentNodeOfType(layoutSection)(selection) || findSelectedNodeOfType([layoutSection])(selection);
17
+ };
@@ -53,6 +53,14 @@ var getWidthsForPreset = function getWidthsForPreset(presetLayout) {
53
53
  }
54
54
  return [];
55
55
  };
56
+ var isValidLayoutWidthDistributions = function isValidLayoutWidthDistributions(layoutSection) {
57
+ var totalWidth = mapChildren(layoutSection, function (column) {
58
+ return column.attrs.width;
59
+ }).reduce(function (total, width) {
60
+ return total + width;
61
+ }, 0);
62
+ return Math.round(totalWidth) === 100;
63
+ };
56
64
 
57
65
  /**
58
66
  * Finds layout preset based on the width attrs of all the layoutColumn nodes
@@ -361,6 +369,9 @@ export var setPresetLayout = function setPresetLayout(editorAnalyticsAPI) {
361
369
  };
362
370
  };
363
371
  function layoutNeedChanges(node) {
372
+ if (isPreRelease2()) {
373
+ return !getPresetLayout(node) || !isValidLayoutWidthDistributions(node);
374
+ }
364
375
  return !getPresetLayout(node);
365
376
  }
366
377
  function getLayoutChange(node, pos, schema) {
@@ -388,6 +399,7 @@ export var fixColumnSizes = function fixColumnSizes(changedTr, state) {
388
399
  if (node.type !== layoutSection) {
389
400
  return true; // Check all internal nodes expect for layout section
390
401
  }
402
+
391
403
  // Node is a section
392
404
  if (layoutNeedChanges(node)) {
393
405
  change = getLayoutChange(node, pos, state.schema);
@@ -6,9 +6,10 @@ 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
8
  import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
9
- import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
9
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
10
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
11
11
  import { fixColumnSizes, fixColumnStructure, getSelectedLayout } from '../actions';
12
+ import { getMaybeLayoutSection } from '../utils';
12
13
  import { pluginKey } from './plugin-key';
13
14
  export var DEFAULT_LAYOUT = 'two_equal';
14
15
  var isWholeSelectionInsideLayoutColumn = function isWholeSelectionInsideLayoutColumn(state) {
@@ -44,7 +45,7 @@ var getNodeDecoration = function getNodeDecoration(pos, node) {
44
45
  })];
45
46
  };
46
47
  var getInitialPluginState = function getInitialPluginState(options, state) {
47
- var maybeLayoutSection = findParentNodeOfType(state.schema.nodes.layoutSection)(state.selection);
48
+ var maybeLayoutSection = getMaybeLayoutSection(state);
48
49
  var allowBreakout = options.allowBreakout || false;
49
50
  var addSidebarLayouts = options.UNSAFE_addSidebarLayouts || false;
50
51
  var allowSingleColumnLayout = options.UNSAFE_allowSingleColumnLayout || false;
@@ -67,9 +68,7 @@ export default (function (options) {
67
68
  },
68
69
  apply: function apply(tr, pluginState, _oldState, newState) {
69
70
  if (tr.docChanged || tr.selectionSet) {
70
- var layoutSection = newState.schema.nodes.layoutSection,
71
- selection = newState.selection;
72
- var maybeLayoutSection = findParentNodeOfType(layoutSection)(selection) || findSelectedNodeOfType([layoutSection])(selection);
71
+ var maybeLayoutSection = getMaybeLayoutSection(newState);
73
72
  var newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
74
73
  pos: maybeLayoutSection ? maybeLayoutSection.pos : null,
75
74
  selectedLayout: getSelectedLayout(maybeLayoutSection && maybeLayoutSection.node, pluginState.selectedLayout)
@@ -172,7 +172,7 @@ export var buildToolbar = function buildToolbar(state, intl, pos, _allowBreakout
172
172
  onClick: setPresetLayout(editorAnalyticsAPI)('five_equal', intl.formatMessage),
173
173
  selected: numberOfColumns === 5
174
174
  }];
175
- var sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns];
175
+ var sidebarTypesByColumns = SIDEBAR_LAYOUT_TYPES_BY_COLUMNS[numberOfColumns] || [];
176
176
  return {
177
177
  title: layoutToolbarTitle,
178
178
  getDomRef: function getDomRef(view) {
@@ -0,0 +1,12 @@
1
+ import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+ export var getMaybeLayoutSection = function getMaybeLayoutSection(state) {
4
+ var _state$schema$nodes = state.schema.nodes,
5
+ layoutSection = _state$schema$nodes.layoutSection,
6
+ layoutColumn = _state$schema$nodes.layoutColumn,
7
+ selection = state.selection;
8
+ var isLayoutColumn = editorExperiment('advanced_layouts', true) && findSelectedNodeOfType([layoutColumn])(selection);
9
+
10
+ // When selection is on layoutColumn, we want to hide floating toolbar, hence don't return layoutSection node here
11
+ return isLayoutColumn ? undefined : findParentNodeOfType(layoutSection)(selection) || findSelectedNodeOfType([layoutSection])(selection);
12
+ };
@@ -0,0 +1,3 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ import { type ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
3
+ export declare const getMaybeLayoutSection: (state: EditorState) => ContentNodeWithPos | undefined;
@@ -0,0 +1,3 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ import { type ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
3
+ export declare const getMaybeLayoutSection: (state: EditorState) => ContentNodeWithPos | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-layout",
3
- "version": "1.12.2",
3
+ "version": "1.12.3",
4
4
  "description": "Layout plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^44.2.0",
35
- "@atlaskit/editor-common": "^94.21.0",
35
+ "@atlaskit/editor-common": "^94.24.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.10.0",
37
37
  "@atlaskit/editor-plugin-decorations": "^1.3.0",
38
38
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/editor-prosemirror": "6.0.0",
41
41
  "@atlaskit/icon": "^22.24.0",
42
42
  "@atlaskit/platform-feature-flags": "^0.3.0",
43
- "@atlaskit/tmp-editor-statsig": "^2.16.0",
43
+ "@atlaskit/tmp-editor-statsig": "^2.19.0",
44
44
  "@atlaskit/tokens": "^2.2.0",
45
45
  "@babel/runtime": "^7.0.0",
46
46
  "@emotion/react": "^11.7.1"