@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-layout
|
|
2
2
|
|
|
3
|
+
## 10.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3b52ed6492f99`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3b52ed6492f99) -
|
|
8
|
+
Fix layout column blank-space focus for vertical alignment
|
|
9
|
+
- [`523f77de83059`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/523f77de83059) -
|
|
10
|
+
Suppress drag handle tooltip while layout column menu is open. Adds layoutColumnMenuPopupOpen user
|
|
11
|
+
intent and wraps LayoutColumnMenu with UserIntentPopupWrapper.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 10.9.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [`10c5beb57bb0d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/10c5beb57bb0d) -
|
|
19
|
+
[ux] Add Distribute columns to the layout floating toolbar
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
|
|
3
25
|
## 10.8.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/cjs/layoutPlugin.js
CHANGED
|
@@ -57,7 +57,7 @@ var selectIntoLayoutSection = exports.selectIntoLayoutSection = function selectI
|
|
|
57
57
|
return tr;
|
|
58
58
|
};
|
|
59
59
|
var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
60
|
-
var _api$analytics;
|
|
60
|
+
var _api$analytics, _api$analytics5;
|
|
61
61
|
var _ref$config = _ref.config,
|
|
62
62
|
options = _ref$config === void 0 ? {} : _ref$config,
|
|
63
63
|
api = _ref.api;
|
|
@@ -381,10 +381,7 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
381
381
|
var _api$analytics4;
|
|
382
382
|
return (0, _actions.deleteLayoutColumn)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(props);
|
|
383
383
|
},
|
|
384
|
-
distributeLayoutColumns:
|
|
385
|
-
var _api$analytics5;
|
|
386
|
-
return (0, _actions.distributeLayoutColumns)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions)(props);
|
|
387
|
-
},
|
|
384
|
+
distributeLayoutColumns: (0, _actions.distributeLayoutColumns)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions),
|
|
388
385
|
insertLayoutColumn: function insertLayoutColumn(side) {
|
|
389
386
|
var _api$analytics6;
|
|
390
387
|
return (0, _actions.insertLayoutColumn)(side, api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions);
|
|
@@ -564,18 +564,17 @@ var insertLayoutColumnAt = function insertLayoutColumnAt(side, editorAnalyticsAP
|
|
|
564
564
|
if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
565
565
|
return null;
|
|
566
566
|
}
|
|
567
|
-
var
|
|
568
|
-
if (!selectedLayoutColumns) {
|
|
567
|
+
var selectedLayoutColumnsResult = (0, _layoutColumnSelection.getSelectedLayoutColumnsFromSelection)(tr.selection);
|
|
568
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length === 0) {
|
|
569
569
|
return null;
|
|
570
570
|
}
|
|
571
|
-
var layoutSectionNode =
|
|
572
|
-
layoutSectionPos =
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
571
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
572
|
+
layoutSectionPos = selectedLayoutColumnsResult.layoutSectionPos,
|
|
573
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
574
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
575
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
577
576
|
var selectedColumnIndex = side === 'left' ? startIndex : endIndex;
|
|
578
|
-
var selectedColumnCount =
|
|
577
|
+
var selectedColumnCount = selectedLayoutColumns.length;
|
|
579
578
|
if (layoutSectionNode.childCount >= getEffectiveMaxLayoutColumns()) {
|
|
580
579
|
return null;
|
|
581
580
|
}
|
|
@@ -633,22 +632,20 @@ var setLayoutColumnValign = exports.setLayoutColumnValign = function setLayoutCo
|
|
|
633
632
|
if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
634
633
|
return null;
|
|
635
634
|
}
|
|
636
|
-
var
|
|
637
|
-
if (!
|
|
635
|
+
var selectedLayoutColumnsResult = (0, _layoutColumnSelection.getSelectedLayoutColumnsFromSelection)(tr.selection);
|
|
636
|
+
if (!selectedLayoutColumnsResult) {
|
|
638
637
|
return null;
|
|
639
638
|
}
|
|
640
|
-
var
|
|
641
|
-
|
|
642
|
-
|
|
639
|
+
var startIndex = selectedLayoutColumnsResult.startIndex,
|
|
640
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
641
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
642
|
+
var columnsToUpdate = selectedLayoutColumns.filter(function (_ref6) {
|
|
643
643
|
var node = _ref6.node;
|
|
644
644
|
return node.attrs.valign !== valign;
|
|
645
645
|
});
|
|
646
646
|
if (columnsToUpdate.length === 0) {
|
|
647
647
|
return null;
|
|
648
648
|
}
|
|
649
|
-
var startIndex = selectedColumnIndices[0];
|
|
650
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
651
|
-
var selectedColumnCount = selectedColumns.length;
|
|
652
649
|
var updatedColumnCount = columnsToUpdate.length;
|
|
653
650
|
columnsToUpdate.forEach(function (_ref7) {
|
|
654
651
|
var node = _ref7.node,
|
|
@@ -664,7 +661,7 @@ var setLayoutColumnValign = exports.setLayoutColumnValign = function setLayoutCo
|
|
|
664
661
|
attributes: {
|
|
665
662
|
endIndex: endIndex,
|
|
666
663
|
inputMethod: _analytics.INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
667
|
-
selectedCount:
|
|
664
|
+
selectedCount: selectedLayoutColumns.length,
|
|
668
665
|
startIndex: startIndex,
|
|
669
666
|
updatedCount: updatedColumnCount,
|
|
670
667
|
valign: valign
|
|
@@ -676,89 +673,92 @@ var setLayoutColumnValign = exports.setLayoutColumnValign = function setLayoutCo
|
|
|
676
673
|
};
|
|
677
674
|
};
|
|
678
675
|
var distributeLayoutColumns = exports.distributeLayoutColumns = function distributeLayoutColumns(editorAnalyticsAPI) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
var layoutSectionNode = selectedLayoutColumns.layoutSectionNode,
|
|
690
|
-
selectedColumnIndices = selectedLayoutColumns.selectedColumnIndices,
|
|
691
|
-
selectedColumns = selectedLayoutColumns.selectedColumns;
|
|
692
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
693
|
-
var selectedColumnCount = selectedColumns.length;
|
|
694
|
-
var totalColumnCount = layoutSectionNode.childCount;
|
|
695
|
-
var existingWidths = (0, _utils.mapChildren)(layoutSectionNode, function (column) {
|
|
696
|
-
return column.attrs.width;
|
|
697
|
-
});
|
|
698
|
-
var selectedWidths = selectedColumns.map(function (_ref9) {
|
|
699
|
-
var node = _ref9.node;
|
|
700
|
-
return node.attrs.width;
|
|
701
|
-
});
|
|
702
|
-
var distribution = (0, _layoutColumnDistribution.calculateDistribution)(selectedWidths);
|
|
703
|
-
if (!distribution) {
|
|
704
|
-
return null;
|
|
705
|
-
}
|
|
706
|
-
var selectedTotal = distribution.selectedTotal,
|
|
707
|
-
equalWidth = distribution.equalWidth;
|
|
708
|
-
if ((0, _layoutColumnDistribution.isDistributedUniformly)(selectedWidths, distribution)) {
|
|
709
|
-
return null;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
// Build new widths array: selected columns get equal share, unselected unchanged.
|
|
713
|
-
// Assign rounded (2dp) equal widths to all selected cols except the last, which absorbs
|
|
714
|
-
// the rounding remainder so the sum of selected widths equals selectedTotal exactly.
|
|
715
|
-
var selectedIndexSet = new Set(selectedColumnIndices);
|
|
716
|
-
var assignedToSelected = 0;
|
|
717
|
-
var selectedAssignedCount = 0;
|
|
718
|
-
var newWidths = existingWidths.map(function (w, idx) {
|
|
719
|
-
if (!selectedIndexSet.has(idx)) {
|
|
720
|
-
return w;
|
|
676
|
+
return function () {
|
|
677
|
+
var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
678
|
+
_ref8$inputMethod = _ref8.inputMethod,
|
|
679
|
+
inputMethod = _ref8$inputMethod === void 0 ? _analytics.INPUT_METHOD.LAYOUT_COLUMN_MENU : _ref8$inputMethod,
|
|
680
|
+
_ref8$target = _ref8.target,
|
|
681
|
+
target = _ref8$target === void 0 ? 'selectedColumns' : _ref8$target;
|
|
682
|
+
return function (_ref9) {
|
|
683
|
+
var tr = _ref9.tr;
|
|
684
|
+
if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
685
|
+
return null;
|
|
721
686
|
}
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
|
|
725
|
-
|
|
687
|
+
var selectedLayoutColumnsResult = target === 'allColumns' ? (0, _layoutColumnSelection.getAllLayoutColumnsFromSelection)(tr.selection) : (0, _layoutColumnSelection.getSelectedLayoutColumnsFromSelection)(tr.selection);
|
|
688
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length < 2) {
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
692
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
693
|
+
endIndex = selectedLayoutColumnsResult.endIndex,
|
|
694
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns;
|
|
695
|
+
var existingWidths = (0, _utils.mapChildren)(layoutSectionNode, function (column) {
|
|
696
|
+
return column.attrs.width;
|
|
697
|
+
});
|
|
698
|
+
var selectedWidths = selectedLayoutColumns.map(function (_ref0) {
|
|
699
|
+
var node = _ref0.node;
|
|
700
|
+
return node.attrs.width;
|
|
701
|
+
});
|
|
702
|
+
var distribution = (0, _layoutColumnDistribution.calculateDistribution)(selectedWidths);
|
|
703
|
+
if (!distribution) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
var selectedTotal = distribution.selectedTotal,
|
|
707
|
+
equalWidth = distribution.equalWidth;
|
|
708
|
+
if ((0, _layoutColumnDistribution.isDistributedUniformly)(selectedWidths, distribution)) {
|
|
709
|
+
return null;
|
|
726
710
|
}
|
|
727
|
-
// Last selected column: absorb the remainder to avoid drift
|
|
728
|
-
return Number((selectedTotal - assignedToSelected).toFixed(2));
|
|
729
|
-
});
|
|
730
711
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
var
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
712
|
+
// Build new widths array: selected columns get equal share, unselected unchanged.
|
|
713
|
+
// Assign rounded (2dp) equal widths to all selected cols except the last, which absorbs
|
|
714
|
+
// the rounding remainder so the sum of selected widths equals selectedTotal exactly.
|
|
715
|
+
var assignedToSelected = 0;
|
|
716
|
+
var selectedAssignedCount = 0;
|
|
717
|
+
var newWidths = existingWidths.map(function (w, idx) {
|
|
718
|
+
if (idx < startIndex || idx > endIndex) {
|
|
719
|
+
return w;
|
|
720
|
+
}
|
|
721
|
+
selectedAssignedCount += 1;
|
|
722
|
+
if (selectedAssignedCount < selectedLayoutColumns.length) {
|
|
723
|
+
assignedToSelected += equalWidth;
|
|
724
|
+
return equalWidth;
|
|
725
|
+
}
|
|
726
|
+
// Last selected column: absorb the remainder to avoid drift
|
|
727
|
+
return Number((selectedTotal - assignedToSelected).toFixed(2));
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
// Apply widths via setNodeMarkup per selected column — keeps nodes in place (preserves identity, marks, decorations)
|
|
731
|
+
selectedLayoutColumns.forEach(function (_ref1, i) {
|
|
732
|
+
var node = _ref1.node,
|
|
733
|
+
pos = _ref1.pos;
|
|
734
|
+
var colIdx = startIndex + i;
|
|
735
|
+
tr.setNodeMarkup(pos, node.type, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
736
|
+
width: newWidths[colIdx]
|
|
737
|
+
}));
|
|
738
|
+
});
|
|
739
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
740
|
+
action: _analytics.ACTION.UPDATED,
|
|
741
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
742
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.LAYOUT_COLUMN,
|
|
743
|
+
attributes: {
|
|
744
|
+
columnCount: layoutSectionNode.childCount,
|
|
745
|
+
endIndex: endIndex,
|
|
746
|
+
inputMethod: inputMethod,
|
|
747
|
+
selectedCount: selectedLayoutColumns.length,
|
|
748
|
+
startIndex: startIndex
|
|
749
|
+
},
|
|
750
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
751
|
+
})(tr);
|
|
752
|
+
tr.setMeta('scrollIntoView', false);
|
|
753
|
+
return tr;
|
|
754
|
+
};
|
|
755
755
|
};
|
|
756
756
|
};
|
|
757
|
-
var toggleLayoutColumnMenu = exports.toggleLayoutColumnMenu = function toggleLayoutColumnMenu(
|
|
758
|
-
var anchorPos =
|
|
759
|
-
isOpen =
|
|
760
|
-
return function (
|
|
761
|
-
var tr =
|
|
757
|
+
var toggleLayoutColumnMenu = exports.toggleLayoutColumnMenu = function toggleLayoutColumnMenu(_ref10) {
|
|
758
|
+
var anchorPos = _ref10.anchorPos,
|
|
759
|
+
isOpen = _ref10.isOpen;
|
|
760
|
+
return function (_ref11) {
|
|
761
|
+
var tr = _ref11.tr;
|
|
762
762
|
tr.setMeta('toggleLayoutColumnMenu', {
|
|
763
763
|
anchorPos: anchorPos,
|
|
764
764
|
isOpen: isOpen
|
|
@@ -768,23 +768,20 @@ var toggleLayoutColumnMenu = exports.toggleLayoutColumnMenu = function toggleLay
|
|
|
768
768
|
};
|
|
769
769
|
};
|
|
770
770
|
var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI) {
|
|
771
|
-
return function (
|
|
772
|
-
var tr =
|
|
771
|
+
return function (_ref12) {
|
|
772
|
+
var tr = _ref12.tr;
|
|
773
773
|
if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
774
774
|
return null;
|
|
775
775
|
}
|
|
776
|
-
var
|
|
777
|
-
if (!selectedLayoutColumns) {
|
|
776
|
+
var selectedLayoutColumnsResult = (0, _layoutColumnSelection.getSelectedLayoutColumnsFromSelection)(tr.selection);
|
|
777
|
+
if (!selectedLayoutColumnsResult || selectedLayoutColumnsResult.selectedLayoutColumns.length === 0) {
|
|
778
778
|
return null;
|
|
779
779
|
}
|
|
780
|
-
var layoutSectionNode =
|
|
781
|
-
layoutSectionPos =
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
var endIndex = selectedColumnIndices[selectedColumnIndices.length - 1];
|
|
786
|
-
var selectedColumnCount = selectedColumns.length;
|
|
787
|
-
var selectedColumnIndexSet = new Set(selectedColumnIndices);
|
|
780
|
+
var layoutSectionNode = selectedLayoutColumnsResult.layoutSectionNode,
|
|
781
|
+
layoutSectionPos = selectedLayoutColumnsResult.layoutSectionPos,
|
|
782
|
+
selectedLayoutColumns = selectedLayoutColumnsResult.selectedLayoutColumns,
|
|
783
|
+
startIndex = selectedLayoutColumnsResult.startIndex,
|
|
784
|
+
endIndex = selectedLayoutColumnsResult.endIndex;
|
|
788
785
|
var emitDeleteColumnAnalytics = function emitDeleteColumnAnalytics(columnCount) {
|
|
789
786
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
790
787
|
action: _analytics.ACTION.DELETED,
|
|
@@ -794,7 +791,7 @@ var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColum
|
|
|
794
791
|
columnCount: columnCount,
|
|
795
792
|
endIndex: endIndex,
|
|
796
793
|
inputMethod: _analytics.INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
797
|
-
selectedCount:
|
|
794
|
+
selectedCount: selectedLayoutColumns.length,
|
|
798
795
|
startIndex: startIndex
|
|
799
796
|
},
|
|
800
797
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
@@ -802,7 +799,7 @@ var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColum
|
|
|
802
799
|
};
|
|
803
800
|
|
|
804
801
|
// If all columns are selected, remove the entire layoutSection
|
|
805
|
-
if (
|
|
802
|
+
if (selectedLayoutColumns.length === layoutSectionNode.childCount) {
|
|
806
803
|
tr.delete(layoutSectionPos, layoutSectionPos + layoutSectionNode.nodeSize);
|
|
807
804
|
emitDeleteColumnAnalytics(0);
|
|
808
805
|
tr.setMeta('scrollIntoView', false);
|
|
@@ -812,7 +809,7 @@ var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColum
|
|
|
812
809
|
// Build new column list without the selected columns
|
|
813
810
|
var remainingColumns = [];
|
|
814
811
|
layoutSectionNode.forEach(function (column, _offset, index) {
|
|
815
|
-
if (
|
|
812
|
+
if (index < startIndex || index > endIndex) {
|
|
816
813
|
remainingColumns.push(column);
|
|
817
814
|
}
|
|
818
815
|
});
|
|
@@ -821,12 +818,12 @@ var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColum
|
|
|
821
818
|
var existingWidths = (0, _utils.mapChildren)(layoutSectionNode, function (column) {
|
|
822
819
|
return column.attrs.width;
|
|
823
820
|
});
|
|
824
|
-
var redistributed =
|
|
821
|
+
var redistributed = selectedLayoutColumns.map(function (_, i) {
|
|
822
|
+
return startIndex + i;
|
|
823
|
+
})
|
|
825
824
|
// Delete highest indices first so lower original indices still point at the same columns
|
|
826
825
|
// as each redistribution step shrinks the widths array.
|
|
827
|
-
.
|
|
828
|
-
return b - a;
|
|
829
|
-
}).reduce(function (widths, selectedIndex) {
|
|
826
|
+
.reverse().reduce(function (widths, selectedIndex) {
|
|
830
827
|
return (0, _layoutColumnDistribution.redistributeAfterDeletion)(widths, selectedIndex, _consts.MIN_LAYOUT_COLUMN_WIDTH_PERCENT);
|
|
831
828
|
}, existingWidths);
|
|
832
829
|
var updatedLayoutSectionNode = layoutSectionNode.copy(_model.Fragment.fromArray(remainingColumns));
|
|
@@ -3,127 +3,94 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getSelectedLayoutColumnsFromSelection = exports.getLayoutColumnValign = exports.getLayoutColumnMenuAnchorPos = exports.getAllLayoutColumnsFromSelection = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (isLayoutColumn($pos.node(depth)) && isLayoutSection($pos.node(depth - 1))) {
|
|
18
|
-
return $pos.index(depth - 1);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return undefined;
|
|
22
|
-
};
|
|
23
|
-
var getLayoutSectionDepth = function getLayoutSectionDepth(selection) {
|
|
24
|
-
var $from = selection.$from,
|
|
25
|
-
$to = selection.$to;
|
|
26
|
-
var sharedDepth = $from.sharedDepth($to.pos);
|
|
27
|
-
for (var depth = sharedDepth; depth > 0; depth--) {
|
|
28
|
-
if (isLayoutSection($from.node(depth))) {
|
|
29
|
-
return depth;
|
|
30
|
-
}
|
|
8
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var findLayoutSectionFromSelection = function findLayoutSectionFromSelection(selection) {
|
|
10
|
+
var layoutSection = selection.$from.doc.type.schema.nodes.layoutSection;
|
|
11
|
+
// NodeSelection on the layoutSection node itself
|
|
12
|
+
if (selection instanceof _state.NodeSelection && selection.node.type === layoutSection) {
|
|
13
|
+
return {
|
|
14
|
+
node: selection.node,
|
|
15
|
+
pos: selection.from
|
|
16
|
+
};
|
|
31
17
|
}
|
|
32
|
-
return
|
|
18
|
+
return (0, _utils.findParentNodeOfType)(layoutSection)(selection);
|
|
33
19
|
};
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var _$from = selection.$from;
|
|
40
|
-
var _layoutSectionNode = _$from.parent;
|
|
41
|
-
if (!isLayoutSection(_layoutSectionNode)) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
var selectedColumnIndex = _$from.index(_$from.depth);
|
|
20
|
+
var findLayoutColumnsFromLayoutSection = function findLayoutColumnsFromLayoutSection(layoutSectionNode) {
|
|
21
|
+
var layoutSectionPos = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
22
|
+
return (0, _utils.findChildrenByType)(layoutSectionNode, layoutSectionNode.type.schema.nodes.layoutColumn).map(function (_ref) {
|
|
23
|
+
var node = _ref.node,
|
|
24
|
+
pos = _ref.pos;
|
|
45
25
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
selectedColumnIndices: [selectedColumnIndex],
|
|
49
|
-
selectedColumns: [{
|
|
50
|
-
index: selectedColumnIndex,
|
|
51
|
-
node: selection.node,
|
|
52
|
-
pos: selection.from
|
|
53
|
-
}]
|
|
26
|
+
node: node,
|
|
27
|
+
pos: pos + layoutSectionPos + 1
|
|
54
28
|
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var getSelectedLayoutColumnsFromSelection = exports.getSelectedLayoutColumnsFromSelection = function getSelectedLayoutColumnsFromSelection(selection) {
|
|
32
|
+
var layoutSection = findLayoutSectionFromSelection(selection);
|
|
33
|
+
if (!layoutSection) {
|
|
60
34
|
return undefined;
|
|
61
35
|
}
|
|
62
|
-
var
|
|
63
|
-
|
|
36
|
+
var layoutSectionNode = layoutSection.node,
|
|
37
|
+
layoutSectionPos = layoutSection.pos;
|
|
38
|
+
var allLayoutColumns = findLayoutColumnsFromLayoutSection(layoutSectionNode, layoutSectionPos);
|
|
39
|
+
if (!allLayoutColumns.length) {
|
|
64
40
|
return undefined;
|
|
65
41
|
}
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (!isLayoutColumn(column)) {
|
|
80
|
-
invalidSelection = true;
|
|
81
|
-
return;
|
|
42
|
+
var startIndex = -1;
|
|
43
|
+
var endIndex = -1;
|
|
44
|
+
var selectedLayoutColumns = allLayoutColumns.filter(function (_ref2, index) {
|
|
45
|
+
var node = _ref2.node,
|
|
46
|
+
pos = _ref2.pos;
|
|
47
|
+
var isSelected = selection.from <= pos && selection.to >= pos + node.nodeSize;
|
|
48
|
+
if (isSelected) {
|
|
49
|
+
if (startIndex === -1) {
|
|
50
|
+
startIndex = index;
|
|
51
|
+
}
|
|
52
|
+
endIndex = index;
|
|
82
53
|
}
|
|
83
|
-
|
|
84
|
-
index: index,
|
|
85
|
-
node: column,
|
|
86
|
-
pos: columnStart
|
|
87
|
-
});
|
|
54
|
+
return isSelected;
|
|
88
55
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
56
|
+
return {
|
|
57
|
+
layoutSectionNode: layoutSectionNode,
|
|
58
|
+
layoutSectionPos: layoutSectionPos,
|
|
59
|
+
selectedLayoutColumns: selectedLayoutColumns,
|
|
60
|
+
startIndex: startIndex,
|
|
61
|
+
endIndex: endIndex
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
var getAllLayoutColumnsFromSelection = exports.getAllLayoutColumnsFromSelection = function getAllLayoutColumnsFromSelection(selection) {
|
|
65
|
+
var layoutSection = findLayoutSectionFromSelection(selection);
|
|
66
|
+
if (!layoutSection) {
|
|
92
67
|
return undefined;
|
|
93
68
|
}
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
var startColumnIndex = getLayoutColumnIndexAtPos($from);
|
|
97
|
-
var endColumnIndex = getLayoutColumnIndexAtPos($to);
|
|
98
|
-
if (startColumnIndex !== undefined && startColumnIndex !== firstColumn.index || endColumnIndex !== undefined && endColumnIndex !== lastColumn.index) {
|
|
69
|
+
var layoutColumns = findLayoutColumnsFromLayoutSection(layoutSection.node, layoutSection.pos);
|
|
70
|
+
if (!(layoutColumns !== null && layoutColumns !== void 0 && layoutColumns.length)) {
|
|
99
71
|
return undefined;
|
|
100
72
|
}
|
|
101
73
|
return {
|
|
102
|
-
layoutSectionNode:
|
|
103
|
-
layoutSectionPos:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}),
|
|
108
|
-
selectedColumns: selectedColumns
|
|
74
|
+
layoutSectionNode: layoutSection.node,
|
|
75
|
+
layoutSectionPos: layoutSection.pos,
|
|
76
|
+
selectedLayoutColumns: layoutColumns,
|
|
77
|
+
startIndex: 0,
|
|
78
|
+
endIndex: layoutColumns.length - 1
|
|
109
79
|
};
|
|
110
80
|
};
|
|
111
|
-
var getLayoutSectionColumnCount = exports.getLayoutSectionColumnCount = function getLayoutSectionColumnCount(layoutSection) {
|
|
112
|
-
return (layoutSection === null || layoutSection === void 0 ? void 0 : layoutSection.type.name) === 'layoutSection' ? layoutSection.childCount : 0;
|
|
113
|
-
};
|
|
114
81
|
var getLayoutColumnValign = exports.getLayoutColumnValign = function getLayoutColumnValign(layoutColumn) {
|
|
115
|
-
var
|
|
116
|
-
return layoutColumn ? (
|
|
82
|
+
var _ref3;
|
|
83
|
+
return layoutColumn ? (_ref3 = layoutColumn.attrs.valign) !== null && _ref3 !== void 0 ? _ref3 : 'top' : undefined;
|
|
117
84
|
};
|
|
118
85
|
var getLayoutColumnMenuAnchorPos = exports.getLayoutColumnMenuAnchorPos = function getLayoutColumnMenuAnchorPos(selection, anchorPosFromHandle) {
|
|
119
86
|
var _clickedSelectedColum, _selectedLayoutColumn;
|
|
120
|
-
var selectedLayoutColumns =
|
|
87
|
+
var selectedLayoutColumns = getSelectedLayoutColumnsFromSelection(selection);
|
|
121
88
|
if (!selectedLayoutColumns) {
|
|
122
89
|
return undefined;
|
|
123
90
|
}
|
|
124
|
-
var clickedSelectedColumn = selectedLayoutColumns.
|
|
125
|
-
var pos =
|
|
91
|
+
var clickedSelectedColumn = selectedLayoutColumns.selectedLayoutColumns.find(function (_ref4) {
|
|
92
|
+
var pos = _ref4.pos;
|
|
126
93
|
return pos === anchorPosFromHandle;
|
|
127
94
|
});
|
|
128
|
-
return (_clickedSelectedColum = clickedSelectedColumn === null || clickedSelectedColumn === void 0 ? void 0 : clickedSelectedColumn.pos) !== null && _clickedSelectedColum !== void 0 ? _clickedSelectedColum : (_selectedLayoutColumn = selectedLayoutColumns.
|
|
95
|
+
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;
|
|
129
96
|
};
|
|
@@ -36,9 +36,14 @@ var DeleteColumnDropdownItem = exports.DeleteColumnDropdownItem = function Delet
|
|
|
36
36
|
if (selectedLayoutColumns === undefined) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
-
var selectedColumnCount = selectedLayoutColumns.
|
|
39
|
+
var selectedColumnCount = selectedLayoutColumns.selectedLayoutColumns.length;
|
|
40
40
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
41
|
-
onClick: onClick
|
|
41
|
+
onClick: onClick,
|
|
42
|
+
elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.DeleteIcon, {
|
|
43
|
+
color: "currentColor",
|
|
44
|
+
label: "",
|
|
45
|
+
size: "small"
|
|
46
|
+
})
|
|
42
47
|
}, formatMessage(_messages.layoutMessages.deleteColumn, {
|
|
43
48
|
count: selectedColumnCount
|
|
44
49
|
}));
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.DistributeColumnsDropdownItem = void 0;
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _reactIntl = require("react-intl");
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
11
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
12
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
12
13
|
var _layoutColumnDistribution = require("../../pm-plugins/utils/layout-column-distribution");
|
|
@@ -16,12 +17,16 @@ var DistributeColumnsDropdownItem = exports.DistributeColumnsDropdownItem = func
|
|
|
16
17
|
var api = _ref.api;
|
|
17
18
|
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
18
19
|
formatMessage = _useIntl.formatMessage;
|
|
19
|
-
var
|
|
20
|
+
var selectedLayoutColumnsResult = (0, _useSelectedLayoutColumns.useSelectedLayoutColumns)(api);
|
|
21
|
+
var _ref2 = selectedLayoutColumnsResult !== null && selectedLayoutColumnsResult !== void 0 ? selectedLayoutColumnsResult : {},
|
|
22
|
+
selectedLayoutColumns = _ref2.selectedLayoutColumns;
|
|
20
23
|
var handleClick = (0, _react.useCallback)(function () {
|
|
21
24
|
var _api$core;
|
|
22
25
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (props) {
|
|
23
26
|
var _api$layout, _api$layout2;
|
|
24
|
-
var tr = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.distributeLayoutColumns(
|
|
27
|
+
var tr = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.distributeLayoutColumns({
|
|
28
|
+
inputMethod: _analytics.INPUT_METHOD.LAYOUT_COLUMN_MENU
|
|
29
|
+
})(props);
|
|
25
30
|
if (!tr) {
|
|
26
31
|
return null;
|
|
27
32
|
}
|
|
@@ -34,19 +39,24 @@ var DistributeColumnsDropdownItem = exports.DistributeColumnsDropdownItem = func
|
|
|
34
39
|
});
|
|
35
40
|
}, [api]);
|
|
36
41
|
var isAlreadyUniform = (0, _react.useMemo)(function () {
|
|
37
|
-
if (!selectedLayoutColumns || selectedLayoutColumns.
|
|
42
|
+
if (!selectedLayoutColumns || selectedLayoutColumns.length < 2) {
|
|
38
43
|
return false;
|
|
39
44
|
}
|
|
40
|
-
var selectedWidths = selectedLayoutColumns.
|
|
45
|
+
var selectedWidths = selectedLayoutColumns.map(function (col) {
|
|
41
46
|
return col.node.attrs.width;
|
|
42
47
|
});
|
|
43
48
|
return (0, _layoutColumnDistribution.isDistributedUniformly)(selectedWidths);
|
|
44
49
|
}, [selectedLayoutColumns]);
|
|
45
|
-
if (selectedLayoutColumns === undefined || selectedLayoutColumns.
|
|
50
|
+
if (selectedLayoutColumns === undefined || selectedLayoutColumns.length < 2) {
|
|
46
51
|
return null;
|
|
47
52
|
}
|
|
48
53
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
49
54
|
onClick: handleClick,
|
|
50
|
-
isDisabled: isAlreadyUniform
|
|
55
|
+
isDisabled: isAlreadyUniform,
|
|
56
|
+
elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.TableColumnsDistributeIcon, {
|
|
57
|
+
color: "currentColor",
|
|
58
|
+
label: "",
|
|
59
|
+
size: "small"
|
|
60
|
+
})
|
|
51
61
|
}, formatMessage(_messages.layoutMessages.distributeColumns));
|
|
52
62
|
};
|