@atlaskit/editor-plugin-layout 10.8.1 → 10.9.1
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 +22 -0
- package/dist/cjs/layoutPlugin.js +2 -5
- package/dist/cjs/pm-plugins/actions.js +112 -115
- package/dist/cjs/pm-plugins/utils/layout-column-selection.js +63 -96
- package/dist/cjs/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +7 -2
- package/dist/cjs/ui/LayoutColumnMenu/DistributeColumnsDropdownItem.js +16 -6
- package/dist/cjs/ui/LayoutColumnMenu/InsertColumnDropdownItem.js +4 -4
- package/dist/cjs/ui/LayoutColumnMenu/VerticalAlignDropdownItem.js +1 -1
- package/dist/cjs/ui/LayoutColumnMenu/VerticalAlignNestedMenu.js +2 -2
- package/dist/cjs/ui/LayoutColumnMenu/components.js +20 -9
- package/dist/cjs/ui/LayoutColumnMenu/index.js +6 -2
- package/dist/cjs/ui/LayoutColumnMenu/keys.js +8 -3
- package/dist/cjs/ui/LayoutColumnMenu/useSelectedLayoutColumns.js +4 -3
- package/dist/cjs/ui/LayoutColumnMenu/verticalAlignIcons.js +6 -6
- package/dist/cjs/ui/toolbar.js +69 -11
- package/dist/es2019/layoutPlugin.js +2 -5
- package/dist/es2019/pm-plugins/actions.js +45 -51
- package/dist/es2019/pm-plugins/utils/layout-column-selection.js +62 -91
- package/dist/es2019/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +8 -3
- package/dist/es2019/ui/LayoutColumnMenu/DistributeColumnsDropdownItem.js +18 -7
- package/dist/es2019/ui/LayoutColumnMenu/InsertColumnDropdownItem.js +4 -4
- package/dist/es2019/ui/LayoutColumnMenu/VerticalAlignDropdownItem.js +1 -1
- package/dist/es2019/ui/LayoutColumnMenu/VerticalAlignNestedMenu.js +2 -2
- package/dist/es2019/ui/LayoutColumnMenu/components.js +23 -10
- package/dist/es2019/ui/LayoutColumnMenu/index.js +6 -2
- package/dist/es2019/ui/LayoutColumnMenu/keys.js +10 -3
- package/dist/es2019/ui/LayoutColumnMenu/useSelectedLayoutColumns.js +6 -4
- package/dist/es2019/ui/LayoutColumnMenu/verticalAlignIcons.js +6 -6
- package/dist/es2019/ui/toolbar.js +67 -11
- package/dist/esm/layoutPlugin.js +3 -6
- package/dist/esm/pm-plugins/actions.js +113 -116
- package/dist/esm/pm-plugins/utils/layout-column-selection.js +62 -95
- package/dist/esm/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +8 -3
- package/dist/esm/ui/LayoutColumnMenu/DistributeColumnsDropdownItem.js +17 -7
- package/dist/esm/ui/LayoutColumnMenu/InsertColumnDropdownItem.js +4 -4
- package/dist/esm/ui/LayoutColumnMenu/VerticalAlignDropdownItem.js +1 -1
- package/dist/esm/ui/LayoutColumnMenu/VerticalAlignNestedMenu.js +2 -2
- package/dist/esm/ui/LayoutColumnMenu/components.js +21 -10
- package/dist/esm/ui/LayoutColumnMenu/index.js +6 -2
- package/dist/esm/ui/LayoutColumnMenu/keys.js +7 -2
- package/dist/esm/ui/LayoutColumnMenu/useSelectedLayoutColumns.js +5 -4
- package/dist/esm/ui/LayoutColumnMenu/verticalAlignIcons.js +6 -6
- package/dist/esm/ui/toolbar.js +70 -12
- package/dist/types/layoutPluginType.d.ts +3 -1
- package/dist/types/pm-plugins/actions.d.ts +5 -1
- package/dist/types/pm-plugins/utils/layout-column-selection.d.ts +9 -8
- package/dist/types/ui/LayoutColumnMenu/keys.d.ts +2 -0
- package/dist/types/ui/LayoutColumnMenu/verticalAlignIcons.d.ts +2 -2
- package/dist/types-ts4.5/layoutPluginType.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +5 -1
- package/dist/types-ts4.5/pm-plugins/utils/layout-column-selection.d.ts +9 -8
- package/dist/types-ts4.5/ui/LayoutColumnMenu/keys.d.ts +2 -0
- package/dist/types-ts4.5/ui/LayoutColumnMenu/verticalAlignIcons.d.ts +2 -2
- package/package.json +4 -3
package/dist/esm/layoutPlugin.js
CHANGED
|
@@ -11,7 +11,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
11
11
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
12
12
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
13
13
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
14
|
-
import { createDefaultLayoutSection, createMultiColumnLayoutSection, deleteLayoutColumn as _deleteLayoutColumn, distributeLayoutColumns
|
|
14
|
+
import { createDefaultLayoutSection, createMultiColumnLayoutSection, deleteLayoutColumn as _deleteLayoutColumn, distributeLayoutColumns, insertLayoutColumn as _insertLayoutColumn, insertLayoutColumnsWithAnalytics, setLayoutColumnValign as _setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
15
15
|
import { default as createLayoutPlugin } from './pm-plugins/main';
|
|
16
16
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
17
17
|
import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
|
|
@@ -50,7 +50,7 @@ export var selectIntoLayoutSection = function selectIntoLayoutSection(tr) {
|
|
|
50
50
|
return tr;
|
|
51
51
|
};
|
|
52
52
|
export var layoutPlugin = function layoutPlugin(_ref) {
|
|
53
|
-
var _api$analytics;
|
|
53
|
+
var _api$analytics, _api$analytics5;
|
|
54
54
|
var _ref$config = _ref.config,
|
|
55
55
|
options = _ref$config === void 0 ? {} : _ref$config,
|
|
56
56
|
api = _ref.api;
|
|
@@ -374,10 +374,7 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
374
374
|
var _api$analytics4;
|
|
375
375
|
return _deleteLayoutColumn(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(props);
|
|
376
376
|
},
|
|
377
|
-
distributeLayoutColumns:
|
|
378
|
-
var _api$analytics5;
|
|
379
|
-
return _distributeLayoutColumns(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)(props);
|
|
380
|
-
},
|
|
377
|
+
distributeLayoutColumns: distributeLayoutColumns(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions),
|
|
381
378
|
insertLayoutColumn: function insertLayoutColumn(side) {
|
|
382
379
|
var _api$analytics6;
|
|
383
380
|
return _insertLayoutColumn(side, api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions);
|
|
@@ -13,7 +13,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
13
13
|
import { EVEN_DISTRIBUTED_COL_WIDTHS, MAX_LAYOUT_COLUMNS, MAX_STANDARD_LAYOUT_COLUMNS, MIN_LAYOUT_COLUMN_WIDTH_PERCENT } from './consts';
|
|
14
14
|
import { pluginKey } from './plugin-key';
|
|
15
15
|
import { calculateDistribution, isDistributedUniformly, redistributeAfterDeletion, redistributeProportionally } from './utils/layout-column-distribution';
|
|
16
|
-
import {
|
|
16
|
+
import { getAllLayoutColumnsFromSelection, getSelectedLayoutColumnsFromSelection } from './utils/layout-column-selection';
|
|
17
17
|
export var ONE_COL_LAYOUTS = ['single'];
|
|
18
18
|
export var TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
|
|
19
19
|
export var THREE_COL_LAYOUTS = ['three_equal', 'three_with_sidebars'];
|
|
@@ -554,18 +554,17 @@ var insertLayoutColumnAt = function insertLayoutColumnAt(side, editorAnalyticsAP
|
|
|
554
554
|
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
555
555
|
return null;
|
|
556
556
|
}
|
|
557
|
-
var
|
|
558
|
-
if (!selectedLayoutColumns) {
|
|
557
|
+
var selectedLayoutColumnsResult = getSelectedLayoutColumnsFromSelection(tr.selection);
|
|
558
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length === 0) {
|
|
559
559
|
return null;
|
|
560
560
|
}
|
|
561
|
-
var layoutSectionNode =
|
|
562
|
-
layoutSectionPos =
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
561
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
562
|
+
layoutSectionPos = selectedLayoutColumnsResult.layoutSectionPos,
|
|
563
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
564
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
565
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
567
566
|
var selectedColumnIndex = side === 'left' ? startIndex : endIndex;
|
|
568
|
-
var selectedColumnCount =
|
|
567
|
+
var selectedColumnCount = selectedLayoutColumns.length;
|
|
569
568
|
if (layoutSectionNode.childCount >= getEffectiveMaxLayoutColumns()) {
|
|
570
569
|
return null;
|
|
571
570
|
}
|
|
@@ -623,22 +622,20 @@ export var setLayoutColumnValign = function setLayoutColumnValign(valign, editor
|
|
|
623
622
|
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
624
623
|
return null;
|
|
625
624
|
}
|
|
626
|
-
var
|
|
627
|
-
if (!
|
|
625
|
+
var selectedLayoutColumnsResult = getSelectedLayoutColumnsFromSelection(tr.selection);
|
|
626
|
+
if (!selectedLayoutColumnsResult) {
|
|
628
627
|
return null;
|
|
629
628
|
}
|
|
630
|
-
var
|
|
631
|
-
|
|
632
|
-
|
|
629
|
+
var startIndex = selectedLayoutColumnsResult.startIndex,
|
|
630
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
631
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
632
|
+
var columnsToUpdate = selectedLayoutColumns.filter(function (_ref6) {
|
|
633
633
|
var node = _ref6.node;
|
|
634
634
|
return node.attrs.valign !== valign;
|
|
635
635
|
});
|
|
636
636
|
if (columnsToUpdate.length === 0) {
|
|
637
637
|
return null;
|
|
638
638
|
}
|
|
639
|
-
var startIndex = selectedColumnIndices[0];
|
|
640
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
641
|
-
var selectedColumnCount = selectedColumns.length;
|
|
642
639
|
var updatedColumnCount = columnsToUpdate.length;
|
|
643
640
|
columnsToUpdate.forEach(function (_ref7) {
|
|
644
641
|
var node = _ref7.node,
|
|
@@ -654,7 +651,7 @@ export var setLayoutColumnValign = function setLayoutColumnValign(valign, editor
|
|
|
654
651
|
attributes: {
|
|
655
652
|
endIndex: endIndex,
|
|
656
653
|
inputMethod: INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
657
|
-
selectedCount:
|
|
654
|
+
selectedCount: selectedLayoutColumns.length,
|
|
658
655
|
startIndex: startIndex,
|
|
659
656
|
updatedCount: updatedColumnCount,
|
|
660
657
|
valign: valign
|
|
@@ -666,89 +663,92 @@ export var setLayoutColumnValign = function setLayoutColumnValign(valign, editor
|
|
|
666
663
|
};
|
|
667
664
|
};
|
|
668
665
|
export var distributeLayoutColumns = function distributeLayoutColumns(editorAnalyticsAPI) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
var layoutSectionNode = selectedLayoutColumns.layoutSectionNode,
|
|
680
|
-
selectedColumnIndices = selectedLayoutColumns.selectedColumnIndices,
|
|
681
|
-
selectedColumns = selectedLayoutColumns.selectedColumns;
|
|
682
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
683
|
-
var selectedColumnCount = selectedColumns.length;
|
|
684
|
-
var totalColumnCount = layoutSectionNode.childCount;
|
|
685
|
-
var existingWidths = mapChildren(layoutSectionNode, function (column) {
|
|
686
|
-
return column.attrs.width;
|
|
687
|
-
});
|
|
688
|
-
var selectedWidths = selectedColumns.map(function (_ref9) {
|
|
689
|
-
var node = _ref9.node;
|
|
690
|
-
return node.attrs.width;
|
|
691
|
-
});
|
|
692
|
-
var distribution = calculateDistribution(selectedWidths);
|
|
693
|
-
if (!distribution) {
|
|
694
|
-
return null;
|
|
695
|
-
}
|
|
696
|
-
var selectedTotal = distribution.selectedTotal,
|
|
697
|
-
equalWidth = distribution.equalWidth;
|
|
698
|
-
if (isDistributedUniformly(selectedWidths, distribution)) {
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// Build new widths array: selected columns get equal share, unselected unchanged.
|
|
703
|
-
// Assign rounded (2dp) equal widths to all selected cols except the last, which absorbs
|
|
704
|
-
// the rounding remainder so the sum of selected widths equals selectedTotal exactly.
|
|
705
|
-
var selectedIndexSet = new Set(selectedColumnIndices);
|
|
706
|
-
var assignedToSelected = 0;
|
|
707
|
-
var selectedAssignedCount = 0;
|
|
708
|
-
var newWidths = existingWidths.map(function (w, idx) {
|
|
709
|
-
if (!selectedIndexSet.has(idx)) {
|
|
710
|
-
return w;
|
|
666
|
+
return function () {
|
|
667
|
+
var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
668
|
+
_ref8$inputMethod = _ref8.inputMethod,
|
|
669
|
+
inputMethod = _ref8$inputMethod === void 0 ? INPUT_METHOD.LAYOUT_COLUMN_MENU : _ref8$inputMethod,
|
|
670
|
+
_ref8$target = _ref8.target,
|
|
671
|
+
target = _ref8$target === void 0 ? 'selectedColumns' : _ref8$target;
|
|
672
|
+
return function (_ref9) {
|
|
673
|
+
var tr = _ref9.tr;
|
|
674
|
+
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
675
|
+
return null;
|
|
711
676
|
}
|
|
712
|
-
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
|
|
677
|
+
var selectedLayoutColumnsResult = target === 'allColumns' ? getAllLayoutColumnsFromSelection(tr.selection) : getSelectedLayoutColumnsFromSelection(tr.selection);
|
|
678
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length < 2) {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
682
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
683
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
684
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
685
|
+
var existingWidths = mapChildren(layoutSectionNode, function (column) {
|
|
686
|
+
return column.attrs.width;
|
|
687
|
+
});
|
|
688
|
+
var selectedWidths = selectedLayoutColumns.map(function (_ref0) {
|
|
689
|
+
var node = _ref0.node;
|
|
690
|
+
return node.attrs.width;
|
|
691
|
+
});
|
|
692
|
+
var distribution = calculateDistribution(selectedWidths);
|
|
693
|
+
if (!distribution) {
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
var selectedTotal = distribution.selectedTotal,
|
|
697
|
+
equalWidth = distribution.equalWidth;
|
|
698
|
+
if (isDistributedUniformly(selectedWidths, distribution)) {
|
|
699
|
+
return null;
|
|
716
700
|
}
|
|
717
|
-
// Last selected column: absorb the remainder to avoid drift
|
|
718
|
-
return Number((selectedTotal - assignedToSelected).toFixed(2));
|
|
719
|
-
});
|
|
720
701
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
var
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
702
|
+
// Build new widths array: selected columns get equal share, unselected unchanged.
|
|
703
|
+
// Assign rounded (2dp) equal widths to all selected cols except the last, which absorbs
|
|
704
|
+
// the rounding remainder so the sum of selected widths equals selectedTotal exactly.
|
|
705
|
+
var assignedToSelected = 0;
|
|
706
|
+
var selectedAssignedCount = 0;
|
|
707
|
+
var newWidths = existingWidths.map(function (w, idx) {
|
|
708
|
+
if (idx < startIndex || idx > endIndex) {
|
|
709
|
+
return w;
|
|
710
|
+
}
|
|
711
|
+
selectedAssignedCount += 1;
|
|
712
|
+
if (selectedAssignedCount < selectedLayoutColumns.length) {
|
|
713
|
+
assignedToSelected += equalWidth;
|
|
714
|
+
return equalWidth;
|
|
715
|
+
}
|
|
716
|
+
// Last selected column: absorb the remainder to avoid drift
|
|
717
|
+
return Number((selectedTotal - assignedToSelected).toFixed(2));
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// Apply widths via setNodeMarkup per selected column — keeps nodes in place (preserves identity, marks, decorations)
|
|
721
|
+
selectedLayoutColumns.forEach(function (_ref1, i) {
|
|
722
|
+
var node = _ref1.node,
|
|
723
|
+
pos = _ref1.pos;
|
|
724
|
+
var colIdx = startIndex + i;
|
|
725
|
+
tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
726
|
+
width: newWidths[colIdx]
|
|
727
|
+
}));
|
|
728
|
+
});
|
|
729
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
730
|
+
action: ACTION.UPDATED,
|
|
731
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
732
|
+
actionSubjectId: ACTION_SUBJECT_ID.LAYOUT_COLUMN,
|
|
733
|
+
attributes: {
|
|
734
|
+
columnCount: layoutSectionNode.childCount,
|
|
735
|
+
endIndex: endIndex,
|
|
736
|
+
inputMethod: inputMethod,
|
|
737
|
+
selectedCount: selectedLayoutColumns.length,
|
|
738
|
+
startIndex: startIndex
|
|
739
|
+
},
|
|
740
|
+
eventType: EVENT_TYPE.TRACK
|
|
741
|
+
})(tr);
|
|
742
|
+
tr.setMeta('scrollIntoView', false);
|
|
743
|
+
return tr;
|
|
744
|
+
};
|
|
745
745
|
};
|
|
746
746
|
};
|
|
747
|
-
export var toggleLayoutColumnMenu = function toggleLayoutColumnMenu(
|
|
748
|
-
var anchorPos =
|
|
749
|
-
isOpen =
|
|
750
|
-
return function (
|
|
751
|
-
var tr =
|
|
747
|
+
export var toggleLayoutColumnMenu = function toggleLayoutColumnMenu(_ref10) {
|
|
748
|
+
var anchorPos = _ref10.anchorPos,
|
|
749
|
+
isOpen = _ref10.isOpen;
|
|
750
|
+
return function (_ref11) {
|
|
751
|
+
var tr = _ref11.tr;
|
|
752
752
|
tr.setMeta('toggleLayoutColumnMenu', {
|
|
753
753
|
anchorPos: anchorPos,
|
|
754
754
|
isOpen: isOpen
|
|
@@ -758,23 +758,20 @@ export var toggleLayoutColumnMenu = function toggleLayoutColumnMenu(_ref1) {
|
|
|
758
758
|
};
|
|
759
759
|
};
|
|
760
760
|
export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI) {
|
|
761
|
-
return function (
|
|
762
|
-
var tr =
|
|
761
|
+
return function (_ref12) {
|
|
762
|
+
var tr = _ref12.tr;
|
|
763
763
|
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
764
764
|
return null;
|
|
765
765
|
}
|
|
766
|
-
var
|
|
767
|
-
if (!selectedLayoutColumns) {
|
|
766
|
+
var selectedLayoutColumnsResult = getSelectedLayoutColumnsFromSelection(tr.selection);
|
|
767
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length === 0) {
|
|
768
768
|
return null;
|
|
769
769
|
}
|
|
770
|
-
var layoutSectionNode =
|
|
771
|
-
layoutSectionPos =
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
776
|
-
var selectedColumnCount = selectedColumns.length;
|
|
777
|
-
var selectedColumnIndexSet = new Set(selectedColumnIndices);
|
|
770
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
771
|
+
layoutSectionPos = selectedLayoutColumnsResult.layoutSectionPos,
|
|
772
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns,
|
|
773
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
774
|
+
endIndex = selectedLayoutColumnsResult.endIndex;
|
|
778
775
|
var emitDeleteColumnAnalytics = function emitDeleteColumnAnalytics(columnCount) {
|
|
779
776
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
780
777
|
action: ACTION.DELETED,
|
|
@@ -784,7 +781,7 @@ export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI)
|
|
|
784
781
|
columnCount: columnCount,
|
|
785
782
|
endIndex: endIndex,
|
|
786
783
|
inputMethod: INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
787
|
-
selectedCount:
|
|
784
|
+
selectedCount: selectedLayoutColumns.length,
|
|
788
785
|
startIndex: startIndex
|
|
789
786
|
},
|
|
790
787
|
eventType: EVENT_TYPE.TRACK
|
|
@@ -792,7 +789,7 @@ export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI)
|
|
|
792
789
|
};
|
|
793
790
|
|
|
794
791
|
// If all columns are selected, remove the entire layoutSection
|
|
795
|
-
if (
|
|
792
|
+
if (selectedLayoutColumns.length === layoutSectionNode.childCount) {
|
|
796
793
|
tr.delete(layoutSectionPos, layoutSectionPos + layoutSectionNode.nodeSize);
|
|
797
794
|
emitDeleteColumnAnalytics(0);
|
|
798
795
|
tr.setMeta('scrollIntoView', false);
|
|
@@ -802,7 +799,7 @@ export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI)
|
|
|
802
799
|
// Build new column list without the selected columns
|
|
803
800
|
var remainingColumns = [];
|
|
804
801
|
layoutSectionNode.forEach(function (column, _offset, index) {
|
|
805
|
-
if (
|
|
802
|
+
if (index < startIndex || index > endIndex) {
|
|
806
803
|
remainingColumns.push(column);
|
|
807
804
|
}
|
|
808
805
|
});
|
|
@@ -811,12 +808,12 @@ export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI)
|
|
|
811
808
|
var existingWidths = mapChildren(layoutSectionNode, function (column) {
|
|
812
809
|
return column.attrs.width;
|
|
813
810
|
});
|
|
814
|
-
var redistributed =
|
|
811
|
+
var redistributed = selectedLayoutColumns.map(function (_, i) {
|
|
812
|
+
return startIndex + i;
|
|
813
|
+
})
|
|
815
814
|
// Delete highest indices first so lower original indices still point at the same columns
|
|
816
815
|
// as each redistribution step shrinks the widths array.
|
|
817
|
-
.
|
|
818
|
-
return b - a;
|
|
819
|
-
}).reduce(function (widths, selectedIndex) {
|
|
816
|
+
.reverse().reduce(function (widths, selectedIndex) {
|
|
820
817
|
return redistributeAfterDeletion(widths, selectedIndex, MIN_LAYOUT_COLUMN_WIDTH_PERCENT);
|
|
821
818
|
}, existingWidths);
|
|
822
819
|
var updatedLayoutSectionNode = layoutSectionNode.copy(Fragment.fromArray(remainingColumns));
|
|
@@ -1,123 +1,90 @@
|
|
|
1
1
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import {
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (isLayoutColumn($pos.node(depth)) && isLayoutSection($pos.node(depth - 1))) {
|
|
12
|
-
return $pos.index(depth - 1);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return undefined;
|
|
16
|
-
};
|
|
17
|
-
var getLayoutSectionDepth = function getLayoutSectionDepth(selection) {
|
|
18
|
-
var $from = selection.$from,
|
|
19
|
-
$to = selection.$to;
|
|
20
|
-
var sharedDepth = $from.sharedDepth($to.pos);
|
|
21
|
-
for (var depth = sharedDepth; depth > 0; depth--) {
|
|
22
|
-
if (isLayoutSection($from.node(depth))) {
|
|
23
|
-
return depth;
|
|
24
|
-
}
|
|
2
|
+
import { findChildrenByType, findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
var findLayoutSectionFromSelection = function findLayoutSectionFromSelection(selection) {
|
|
4
|
+
var layoutSection = selection.$from.doc.type.schema.nodes.layoutSection;
|
|
5
|
+
// NodeSelection on the layoutSection node itself
|
|
6
|
+
if (selection instanceof NodeSelection && selection.node.type === layoutSection) {
|
|
7
|
+
return {
|
|
8
|
+
node: selection.node,
|
|
9
|
+
pos: selection.from
|
|
10
|
+
};
|
|
25
11
|
}
|
|
26
|
-
return
|
|
12
|
+
return findParentNodeOfType(layoutSection)(selection);
|
|
27
13
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var _$from = selection.$from;
|
|
34
|
-
var _layoutSectionNode = _$from.parent;
|
|
35
|
-
if (!isLayoutSection(_layoutSectionNode)) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
var selectedColumnIndex = _$from.index(_$from.depth);
|
|
14
|
+
var findLayoutColumnsFromLayoutSection = function findLayoutColumnsFromLayoutSection(layoutSectionNode) {
|
|
15
|
+
var layoutSectionPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
16
|
+
return findChildrenByType(layoutSectionNode, layoutSectionNode.type.schema.nodes.layoutColumn).map(function (_ref) {
|
|
17
|
+
var node = _ref.node,
|
|
18
|
+
pos = _ref.pos;
|
|
39
19
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
selectedColumnIndices: [selectedColumnIndex],
|
|
43
|
-
selectedColumns: [{
|
|
44
|
-
index: selectedColumnIndex,
|
|
45
|
-
node: selection.node,
|
|
46
|
-
pos: selection.from
|
|
47
|
-
}]
|
|
20
|
+
node: node,
|
|
21
|
+
pos: pos + layoutSectionPos + 1
|
|
48
22
|
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export var getSelectedLayoutColumnsFromSelection = function getSelectedLayoutColumnsFromSelection(selection) {
|
|
26
|
+
var layoutSection = findLayoutSectionFromSelection(selection);
|
|
27
|
+
if (!layoutSection) {
|
|
54
28
|
return undefined;
|
|
55
29
|
}
|
|
56
|
-
var
|
|
57
|
-
|
|
30
|
+
var layoutSectionNode = layoutSection.node,
|
|
31
|
+
layoutSectionPos = layoutSection.pos;
|
|
32
|
+
var allLayoutColumns = findLayoutColumnsFromLayoutSection(layoutSectionNode, layoutSectionPos);
|
|
33
|
+
if (!allLayoutColumns.length) {
|
|
58
34
|
return undefined;
|
|
59
35
|
}
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return;
|
|
36
|
+
var startIndex = -1;
|
|
37
|
+
var endIndex = -1;
|
|
38
|
+
var selectedLayoutColumns = allLayoutColumns.filter(function (_ref2, index) {
|
|
39
|
+
var node = _ref2.node,
|
|
40
|
+
pos = _ref2.pos;
|
|
41
|
+
var isSelected = selection.from <= pos && selection.to >= pos + node.nodeSize;
|
|
42
|
+
if (isSelected) {
|
|
43
|
+
if (startIndex === -1) {
|
|
44
|
+
startIndex = index;
|
|
45
|
+
}
|
|
46
|
+
endIndex = index;
|
|
72
47
|
}
|
|
73
|
-
|
|
74
|
-
invalidSelection = true;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
selectedColumns.push({
|
|
78
|
-
index: index,
|
|
79
|
-
node: column,
|
|
80
|
-
pos: columnStart
|
|
81
|
-
});
|
|
48
|
+
return isSelected;
|
|
82
49
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
50
|
+
return {
|
|
51
|
+
layoutSectionNode: layoutSectionNode,
|
|
52
|
+
layoutSectionPos: layoutSectionPos,
|
|
53
|
+
selectedLayoutColumns: selectedLayoutColumns,
|
|
54
|
+
startIndex: startIndex,
|
|
55
|
+
endIndex: endIndex
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export var getAllLayoutColumnsFromSelection = function getAllLayoutColumnsFromSelection(selection) {
|
|
59
|
+
var layoutSection = findLayoutSectionFromSelection(selection);
|
|
60
|
+
if (!layoutSection) {
|
|
86
61
|
return undefined;
|
|
87
62
|
}
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
var startColumnIndex = getLayoutColumnIndexAtPos($from);
|
|
91
|
-
var endColumnIndex = getLayoutColumnIndexAtPos($to);
|
|
92
|
-
if (startColumnIndex !== undefined && startColumnIndex !== firstColumn.index || endColumnIndex !== undefined && endColumnIndex !== lastColumn.index) {
|
|
63
|
+
var layoutColumns = findLayoutColumnsFromLayoutSection(layoutSection.node, layoutSection.pos);
|
|
64
|
+
if (!(layoutColumns !== null && layoutColumns !== void 0 && layoutColumns.length)) {
|
|
93
65
|
return undefined;
|
|
94
66
|
}
|
|
95
67
|
return {
|
|
96
|
-
layoutSectionNode:
|
|
97
|
-
layoutSectionPos:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}),
|
|
102
|
-
selectedColumns: selectedColumns
|
|
68
|
+
layoutSectionNode: layoutSection.node,
|
|
69
|
+
layoutSectionPos: layoutSection.pos,
|
|
70
|
+
selectedLayoutColumns: layoutColumns,
|
|
71
|
+
startIndex: 0,
|
|
72
|
+
endIndex: layoutColumns.length - 1
|
|
103
73
|
};
|
|
104
74
|
};
|
|
105
|
-
export var getLayoutSectionColumnCount = function getLayoutSectionColumnCount(layoutSection) {
|
|
106
|
-
return (layoutSection === null || layoutSection === void 0 ? void 0 : layoutSection.type.name) === 'layoutSection' ? layoutSection.childCount : 0;
|
|
107
|
-
};
|
|
108
75
|
export var getLayoutColumnValign = function getLayoutColumnValign(layoutColumn) {
|
|
109
|
-
var
|
|
110
|
-
return layoutColumn ? (
|
|
76
|
+
var _ref3;
|
|
77
|
+
return layoutColumn ? (_ref3 = layoutColumn.attrs.valign) !== null && _ref3 !== void 0 ? _ref3 : 'top' : undefined;
|
|
111
78
|
};
|
|
112
79
|
export var getLayoutColumnMenuAnchorPos = function getLayoutColumnMenuAnchorPos(selection, anchorPosFromHandle) {
|
|
113
80
|
var _clickedSelectedColum, _selectedLayoutColumn;
|
|
114
|
-
var selectedLayoutColumns =
|
|
81
|
+
var selectedLayoutColumns = getSelectedLayoutColumnsFromSelection(selection);
|
|
115
82
|
if (!selectedLayoutColumns) {
|
|
116
83
|
return undefined;
|
|
117
84
|
}
|
|
118
|
-
var clickedSelectedColumn = selectedLayoutColumns.
|
|
119
|
-
var pos =
|
|
85
|
+
var clickedSelectedColumn = selectedLayoutColumns.selectedLayoutColumns.find(function (_ref4) {
|
|
86
|
+
var pos = _ref4.pos;
|
|
120
87
|
return pos === anchorPosFromHandle;
|
|
121
88
|
});
|
|
122
|
-
return (_clickedSelectedColum = clickedSelectedColumn === null || clickedSelectedColumn === void 0 ? void 0 : clickedSelectedColumn.pos) !== null && _clickedSelectedColum !== void 0 ? _clickedSelectedColum : (_selectedLayoutColumn = selectedLayoutColumns.
|
|
89
|
+
return (_clickedSelectedColum = clickedSelectedColumn === null || clickedSelectedColumn === void 0 ? void 0 : clickedSelectedColumn.pos) !== null && _clickedSelectedColum !== void 0 ? _clickedSelectedColum : (_selectedLayoutColumn = selectedLayoutColumns.selectedLayoutColumns[0]) === null || _selectedLayoutColumn === void 0 ? void 0 : _selectedLayoutColumn.pos;
|
|
123
90
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
-
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
4
|
+
import { DeleteIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
5
|
import { useSelectedLayoutColumns } from './useSelectedLayoutColumns';
|
|
6
6
|
var DeleteColumnDropdownItem = function DeleteColumnDropdownItem(_ref) {
|
|
7
7
|
var api = _ref.api;
|
|
@@ -28,9 +28,14 @@ var DeleteColumnDropdownItem = function DeleteColumnDropdownItem(_ref) {
|
|
|
28
28
|
if (selectedLayoutColumns === undefined) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
var selectedColumnCount = selectedLayoutColumns.
|
|
31
|
+
var selectedColumnCount = selectedLayoutColumns.selectedLayoutColumns.length;
|
|
32
32
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
33
|
-
onClick: onClick
|
|
33
|
+
onClick: onClick,
|
|
34
|
+
elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
35
|
+
color: "currentColor",
|
|
36
|
+
label: "",
|
|
37
|
+
size: "small"
|
|
38
|
+
})
|
|
34
39
|
}, formatMessage(layoutMessages.deleteColumn, {
|
|
35
40
|
count: selectedColumnCount
|
|
36
41
|
}));
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
4
|
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
-
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { TableColumnsDistributeIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
6
|
import { isDistributedUniformly } from '../../pm-plugins/utils/layout-column-distribution';
|
|
6
7
|
import { useSelectedLayoutColumns } from './useSelectedLayoutColumns';
|
|
7
8
|
export var DistributeColumnsDropdownItem = function DistributeColumnsDropdownItem(_ref) {
|
|
8
9
|
var api = _ref.api;
|
|
9
10
|
var _useIntl = useIntl(),
|
|
10
11
|
formatMessage = _useIntl.formatMessage;
|
|
11
|
-
var
|
|
12
|
+
var selectedLayoutColumnsResult = useSelectedLayoutColumns(api);
|
|
13
|
+
var _ref2 = selectedLayoutColumnsResult !== null && selectedLayoutColumnsResult !== void 0 ? selectedLayoutColumnsResult : {},
|
|
14
|
+
selectedLayoutColumns = _ref2.selectedLayoutColumns;
|
|
12
15
|
var handleClick = useCallback(function () {
|
|
13
16
|
var _api$core;
|
|
14
17
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (props) {
|
|
15
18
|
var _api$layout, _api$layout2;
|
|
16
|
-
var tr = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.distributeLayoutColumns(
|
|
19
|
+
var tr = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.distributeLayoutColumns({
|
|
20
|
+
inputMethod: INPUT_METHOD.LAYOUT_COLUMN_MENU
|
|
21
|
+
})(props);
|
|
17
22
|
if (!tr) {
|
|
18
23
|
return null;
|
|
19
24
|
}
|
|
@@ -26,19 +31,24 @@ export var DistributeColumnsDropdownItem = function DistributeColumnsDropdownIte
|
|
|
26
31
|
});
|
|
27
32
|
}, [api]);
|
|
28
33
|
var isAlreadyUniform = useMemo(function () {
|
|
29
|
-
if (!selectedLayoutColumns || selectedLayoutColumns.
|
|
34
|
+
if (!selectedLayoutColumns || selectedLayoutColumns.length < 2) {
|
|
30
35
|
return false;
|
|
31
36
|
}
|
|
32
|
-
var selectedWidths = selectedLayoutColumns.
|
|
37
|
+
var selectedWidths = selectedLayoutColumns.map(function (col) {
|
|
33
38
|
return col.node.attrs.width;
|
|
34
39
|
});
|
|
35
40
|
return isDistributedUniformly(selectedWidths);
|
|
36
41
|
}, [selectedLayoutColumns]);
|
|
37
|
-
if (selectedLayoutColumns === undefined || selectedLayoutColumns.
|
|
42
|
+
if (selectedLayoutColumns === undefined || selectedLayoutColumns.length < 2) {
|
|
38
43
|
return null;
|
|
39
44
|
}
|
|
40
45
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
41
46
|
onClick: handleClick,
|
|
42
|
-
isDisabled: isAlreadyUniform
|
|
47
|
+
isDisabled: isAlreadyUniform,
|
|
48
|
+
elemBefore: /*#__PURE__*/React.createElement(TableColumnsDistributeIcon, {
|
|
49
|
+
color: "currentColor",
|
|
50
|
+
label: "",
|
|
51
|
+
size: "small"
|
|
52
|
+
})
|
|
43
53
|
}, formatMessage(layoutMessages.distributeColumns));
|
|
44
54
|
};
|