@atlaskit/editor-plugin-layout 10.3.5 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/layoutPlugin.js +98 -26
- package/dist/cjs/pm-plugins/actions.js +56 -1
- package/dist/cjs/pm-plugins/utils/redistribute-proportionally.js +31 -1
- package/dist/cjs/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +42 -0
- package/dist/cjs/ui/LayoutColumnMenu/components.js +10 -0
- package/dist/cjs/ui/LayoutColumnMenu/keys.js +6 -2
- package/dist/es2019/layoutPlugin.js +83 -20
- package/dist/es2019/pm-plugins/actions.js +55 -1
- package/dist/es2019/pm-plugins/utils/redistribute-proportionally.js +24 -0
- package/dist/es2019/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +37 -0
- package/dist/es2019/ui/LayoutColumnMenu/components.js +11 -1
- package/dist/es2019/ui/LayoutColumnMenu/keys.js +6 -1
- package/dist/esm/layoutPlugin.js +99 -27
- package/dist/esm/pm-plugins/actions.js +56 -1
- package/dist/esm/pm-plugins/utils/redistribute-proportionally.js +30 -0
- package/dist/esm/ui/LayoutColumnMenu/DeleteColumnDropdownItem.js +35 -0
- package/dist/esm/ui/LayoutColumnMenu/components.js +11 -1
- package/dist/esm/ui/LayoutColumnMenu/keys.js +5 -1
- package/dist/types/layoutPluginType.d.ts +2 -1
- package/dist/types/pm-plugins/actions.d.ts +1 -0
- package/dist/types/pm-plugins/utils/redistribute-proportionally.d.ts +1 -0
- package/dist/types/ui/LayoutColumnMenu/DeleteColumnDropdownItem.d.ts +8 -0
- package/dist/types/ui/LayoutColumnMenu/keys.d.ts +1 -0
- package/dist/types-ts4.5/layoutPluginType.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/utils/redistribute-proportionally.d.ts +1 -0
- package/dist/types-ts4.5/ui/LayoutColumnMenu/DeleteColumnDropdownItem.d.ts +8 -0
- package/dist/types-ts4.5/ui/LayoutColumnMenu/keys.d.ts +1 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-layout
|
|
2
2
|
|
|
3
|
+
## 10.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`bc59bccc2fc5c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/bc59bccc2fc5c) -
|
|
8
|
+
Reorder advanced layout quick insert suggestions
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
14
|
+
## 10.4.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [`6d95dce3d9a86`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6d95dce3d9a86) -
|
|
19
|
+
Add deleteLayoutColumn command to editor-plugin-layout with proportional width redistribution and
|
|
20
|
+
analytics tracking (EDITOR-6669)
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
|
|
3
26
|
## 10.3.5
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/cjs/layoutPlugin.js
CHANGED
|
@@ -15,6 +15,7 @@ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
|
15
15
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
16
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
17
17
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
18
19
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
19
20
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
20
21
|
var _actions = require("./pm-plugins/actions");
|
|
@@ -155,27 +156,94 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
155
156
|
})(tr);
|
|
156
157
|
return tr;
|
|
157
158
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
if ((0, _experiments.editorExperiment)('advanced_layouts', true)) {
|
|
160
|
+
var advancedSingleColumnOption = allowAdvancedSingleColumnLayout ? [{
|
|
161
|
+
id: 'onecolumnlayout',
|
|
162
|
+
title: formatMessage(_messages.layoutMessages.singleColumnAdvancedLayout),
|
|
163
|
+
description: formatMessage(_messages.toolbarInsertBlockMessages.singleColumnsDescriptionAdvancedLayout),
|
|
164
|
+
keywords: ['layout', 'column', 'section', 'single column'],
|
|
165
|
+
priority: 1100,
|
|
166
|
+
icon: function icon() {
|
|
167
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconOneColumnLayout, null);
|
|
168
|
+
},
|
|
169
|
+
action: function action(insert, state) {
|
|
170
|
+
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, 1));
|
|
171
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_column_count_analytics')) {
|
|
172
|
+
withInsertLayoutAnalytics(tr, 1);
|
|
173
|
+
} else {
|
|
174
|
+
withInsertLayoutAnalytics(tr);
|
|
175
|
+
}
|
|
176
|
+
selectIntoLayoutSection(tr);
|
|
177
|
+
return tr;
|
|
173
178
|
}
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
}] : [];
|
|
180
|
+
if ((0, _expValEquals.expValEquals)('platform_editor_layout_typeahead_reorder', 'isEnabled', true)) {
|
|
181
|
+
var createAdvancedColumnLayoutOption = function createAdvancedColumnLayoutOption(_ref4) {
|
|
182
|
+
var columnCount = _ref4.columnCount,
|
|
183
|
+
descriptionColumnCount = _ref4.descriptionColumnCount,
|
|
184
|
+
Icon = _ref4.icon,
|
|
185
|
+
id = _ref4.id,
|
|
186
|
+
keyword = _ref4.keyword,
|
|
187
|
+
title = _ref4.title;
|
|
188
|
+
return {
|
|
189
|
+
id: id,
|
|
190
|
+
title: title,
|
|
191
|
+
description: formatMessage(_messages.toolbarInsertBlockMessages.columnsDescriptionAdvancedLayout, {
|
|
192
|
+
numberOfColumns: descriptionColumnCount
|
|
193
|
+
}),
|
|
194
|
+
keywords: ['layout', 'column', 'section', keyword],
|
|
195
|
+
priority: 1100,
|
|
196
|
+
icon: Icon,
|
|
197
|
+
action: function action(insert, state) {
|
|
198
|
+
var tr = insert((0, _actions.createMultiColumnLayoutSection)(state, columnCount));
|
|
199
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_column_count_analytics')) {
|
|
200
|
+
withInsertLayoutAnalytics(tr, columnCount);
|
|
201
|
+
} else {
|
|
202
|
+
withInsertLayoutAnalytics(tr);
|
|
203
|
+
}
|
|
204
|
+
selectIntoLayoutSection(tr);
|
|
205
|
+
return tr;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
return [createAdvancedColumnLayoutOption({
|
|
210
|
+
columnCount: 2,
|
|
211
|
+
descriptionColumnCount: 'two',
|
|
212
|
+
icon: function icon() {
|
|
213
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconTwoColumnLayout, null);
|
|
214
|
+
},
|
|
215
|
+
id: 'twocolumnslayout',
|
|
216
|
+
keyword: 'two column',
|
|
217
|
+
title: formatMessage(_messages.layoutMessages.twoColumnsAdvancedLayout)
|
|
218
|
+
})].concat(advancedSingleColumnOption, [createAdvancedColumnLayoutOption({
|
|
219
|
+
columnCount: 3,
|
|
220
|
+
descriptionColumnCount: 'three',
|
|
221
|
+
icon: function icon() {
|
|
222
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconThreeColumnLayout, null);
|
|
223
|
+
},
|
|
224
|
+
id: 'threecolumnslayout',
|
|
225
|
+
keyword: 'three column',
|
|
226
|
+
title: formatMessage(_messages.layoutMessages.threeColumnsAdvancedLayout)
|
|
227
|
+
}), createAdvancedColumnLayoutOption({
|
|
228
|
+
columnCount: 4,
|
|
229
|
+
descriptionColumnCount: 'four',
|
|
230
|
+
icon: function icon() {
|
|
231
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconFourColumnLayout, null);
|
|
232
|
+
},
|
|
233
|
+
id: 'fourcolumnslayout',
|
|
234
|
+
keyword: 'four column',
|
|
235
|
+
title: formatMessage(_messages.layoutMessages.fourColumns)
|
|
236
|
+
}), createAdvancedColumnLayoutOption({
|
|
237
|
+
columnCount: 5,
|
|
238
|
+
descriptionColumnCount: 'five',
|
|
239
|
+
icon: function icon() {
|
|
240
|
+
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconFiveColumnLayout, null);
|
|
241
|
+
},
|
|
242
|
+
id: 'fivecolumnslayout',
|
|
243
|
+
keyword: 'five column',
|
|
244
|
+
title: formatMessage(_messages.layoutMessages.fiveColumns)
|
|
245
|
+
})]);
|
|
176
246
|
}
|
|
177
|
-
}] : [];
|
|
178
|
-
if ((0, _experiments.editorExperiment)('advanced_layouts', true)) {
|
|
179
247
|
return [].concat(advancedSingleColumnOption, [{
|
|
180
248
|
id: 'twocolumnslayout',
|
|
181
249
|
title: formatMessage(_messages.layoutMessages.twoColumnsAdvancedLayout),
|
|
@@ -289,11 +357,11 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
289
357
|
}
|
|
290
358
|
}
|
|
291
359
|
},
|
|
292
|
-
contentComponent: function contentComponent(
|
|
293
|
-
var editorView =
|
|
294
|
-
popupsMountPoint =
|
|
295
|
-
popupsBoundariesElement =
|
|
296
|
-
popupsScrollableElement =
|
|
360
|
+
contentComponent: function contentComponent(_ref5) {
|
|
361
|
+
var editorView = _ref5.editorView,
|
|
362
|
+
popupsMountPoint = _ref5.popupsMountPoint,
|
|
363
|
+
popupsBoundariesElement = _ref5.popupsBoundariesElement,
|
|
364
|
+
popupsScrollableElement = _ref5.popupsScrollableElement;
|
|
297
365
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _experiments.editorExperiment)('advanced_layouts', true) ? /*#__PURE__*/_react.default.createElement(_globalStyles.GlobalStylesWrapper, null) : null, (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true) && editorView ? /*#__PURE__*/_react.default.createElement(_LayoutColumnMenu.LayoutColumnMenu, {
|
|
298
366
|
api: api,
|
|
299
367
|
editorView: editorView,
|
|
@@ -309,9 +377,13 @@ var layoutPlugin = exports.layoutPlugin = function layoutPlugin(_ref) {
|
|
|
309
377
|
return _pluginKey.pluginKey.getState(editorState);
|
|
310
378
|
},
|
|
311
379
|
commands: {
|
|
312
|
-
|
|
380
|
+
deleteLayoutColumn: function deleteLayoutColumn(props) {
|
|
313
381
|
var _api$analytics4;
|
|
314
|
-
return (0, _actions.
|
|
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
|
+
},
|
|
384
|
+
insertLayoutColumn: function insertLayoutColumn(side) {
|
|
385
|
+
var _api$analytics5;
|
|
386
|
+
return (0, _actions.insertLayoutColumn)(side, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
315
387
|
},
|
|
316
388
|
setLayoutColumnValign: _actions.setLayoutColumnValign,
|
|
317
389
|
toggleLayoutColumnMenu: _actions.toggleLayoutColumnMenu
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.fixColumnStructure = exports.fixColumnSizes = exports.deleteActiveLayoutNode = exports.createMultiColumnLayoutSection = exports.createDefaultLayoutSection = exports.TWO_COL_LAYOUTS = exports.THREE_COL_LAYOUTS = exports.ONE_COL_LAYOUTS = void 0;
|
|
7
|
+
exports.fixColumnStructure = exports.fixColumnSizes = exports.deleteLayoutColumn = exports.deleteActiveLayoutNode = exports.createMultiColumnLayoutSection = exports.createDefaultLayoutSection = exports.TWO_COL_LAYOUTS = exports.THREE_COL_LAYOUTS = exports.ONE_COL_LAYOUTS = void 0;
|
|
8
8
|
exports.forceSectionToPresetLayout = forceSectionToPresetLayout;
|
|
9
9
|
exports.getEffectiveMaxLayoutColumns = getEffectiveMaxLayoutColumns;
|
|
10
10
|
exports.toggleLayoutColumnMenu = exports.setPresetLayout = exports.setLayoutColumnValign = exports.insertLayoutColumnsWithAnalytics = exports.insertLayoutColumns = exports.insertLayoutColumn = exports.getSelectedLayout = exports.getPresetLayout = void 0;
|
|
@@ -678,4 +678,59 @@ var toggleLayoutColumnMenu = exports.toggleLayoutColumnMenu = function toggleLay
|
|
|
678
678
|
tr.setMeta('scrollIntoView', false);
|
|
679
679
|
return tr;
|
|
680
680
|
};
|
|
681
|
+
};
|
|
682
|
+
var deleteLayoutColumn = exports.deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI) {
|
|
683
|
+
return function (_ref9) {
|
|
684
|
+
var tr = _ref9.tr;
|
|
685
|
+
if (!(0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
686
|
+
return null;
|
|
687
|
+
}
|
|
688
|
+
var selectedColumn = getSelectedLayoutColumnInSection(tr);
|
|
689
|
+
if (!selectedColumn) {
|
|
690
|
+
return null;
|
|
691
|
+
}
|
|
692
|
+
var layoutSectionNode = selectedColumn.layoutSectionNode,
|
|
693
|
+
layoutSectionPos = selectedColumn.layoutSectionPos,
|
|
694
|
+
selectedColumnIndex = selectedColumn.selectedColumnIndex;
|
|
695
|
+
var emitDeleteColumnAnalytics = function emitDeleteColumnAnalytics(columnCount) {
|
|
696
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
697
|
+
action: _analytics.ACTION.DELETED,
|
|
698
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
699
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.LAYOUT_COLUMN,
|
|
700
|
+
attributes: {
|
|
701
|
+
columnCount: columnCount,
|
|
702
|
+
inputMethod: _analytics.INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
703
|
+
selectedIndex: selectedColumnIndex
|
|
704
|
+
},
|
|
705
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
706
|
+
})(tr);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
// If only one column remains, remove the entire layoutSection
|
|
710
|
+
if (layoutSectionNode.childCount === 1) {
|
|
711
|
+
tr.delete(layoutSectionPos, layoutSectionPos + layoutSectionNode.nodeSize);
|
|
712
|
+
emitDeleteColumnAnalytics(0);
|
|
713
|
+
tr.setMeta('scrollIntoView', false);
|
|
714
|
+
return tr;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// Build new column list without the selected column
|
|
718
|
+
var remainingColumns = [];
|
|
719
|
+
layoutSectionNode.forEach(function (column, _offset, index) {
|
|
720
|
+
if (index !== selectedColumnIndex) {
|
|
721
|
+
remainingColumns.push(column);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
// Redistribute widths proportionally among remaining columns using shared utility
|
|
726
|
+
var existingWidths = (0, _utils.mapChildren)(layoutSectionNode, function (column) {
|
|
727
|
+
return column.attrs.width;
|
|
728
|
+
});
|
|
729
|
+
var redistributed = (0, _redistributeProportionally.redistributeAfterDeletion)(existingWidths, selectedColumnIndex, _consts.MIN_LAYOUT_COLUMN_WIDTH_PERCENT);
|
|
730
|
+
var updatedLayoutSectionNode = layoutSectionNode.copy(_model.Fragment.fromArray(remainingColumns));
|
|
731
|
+
tr.replaceWith(layoutSectionPos + 1, layoutSectionPos + layoutSectionNode.nodeSize - 1, columnWidth(updatedLayoutSectionNode, tr.doc.type.schema, redistributed));
|
|
732
|
+
emitDeleteColumnAnalytics(redistributed.length);
|
|
733
|
+
tr.setMeta('scrollIntoView', false);
|
|
734
|
+
return tr;
|
|
735
|
+
};
|
|
681
736
|
};
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.redistributeProportionally = void 0;
|
|
7
|
+
exports.redistributeProportionally = exports.redistributeAfterDeletion = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var roundLayoutColumnWidth = function roundLayoutColumnWidth(width) {
|
|
10
10
|
return Number(width.toFixed(2));
|
|
@@ -81,6 +81,36 @@ var redistributeWithMinimumWidth = function redistributeWithMinimumWidth(_ref) {
|
|
|
81
81
|
});
|
|
82
82
|
return widths;
|
|
83
83
|
};
|
|
84
|
+
var redistributeAfterDeletion = exports.redistributeAfterDeletion = function redistributeAfterDeletion(currentWidths, removeIndex, minWidth) {
|
|
85
|
+
if (currentWidths.length === 0 || removeIndex < 0 || removeIndex >= currentWidths.length || !isValidWidth(minWidth)) {
|
|
86
|
+
return currentWidths;
|
|
87
|
+
}
|
|
88
|
+
if (currentWidths.some(function (width) {
|
|
89
|
+
return !isValidWidth(width);
|
|
90
|
+
})) {
|
|
91
|
+
return currentWidths.filter(function (_, i) {
|
|
92
|
+
return i !== removeIndex;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var remainingWidths = currentWidths.filter(function (_, i) {
|
|
96
|
+
return i !== removeIndex;
|
|
97
|
+
});
|
|
98
|
+
if (remainingWidths.length === 0) {
|
|
99
|
+
return remainingWidths;
|
|
100
|
+
}
|
|
101
|
+
var currentTotalWidth = sumWidths(currentWidths);
|
|
102
|
+
var targetTotalWidth = Math.round(currentTotalWidth) === 100 ? 100 : currentTotalWidth;
|
|
103
|
+
var redistributed = redistributeWithMinimumWidth({
|
|
104
|
+
weights: remainingWidths,
|
|
105
|
+
totalWidth: targetTotalWidth,
|
|
106
|
+
minWidth: minWidth
|
|
107
|
+
});
|
|
108
|
+
if (!redistributed) {
|
|
109
|
+
var equalWidth = roundLayoutColumnWidth(targetTotalWidth / remainingWidths.length);
|
|
110
|
+
return normaliseWidthsTotal(Array(remainingWidths.length).fill(equalWidth), targetTotalWidth, minWidth);
|
|
111
|
+
}
|
|
112
|
+
return normaliseWidthsTotal(redistributed, targetTotalWidth, minWidth);
|
|
113
|
+
};
|
|
84
114
|
var redistributeProportionally = exports.redistributeProportionally = function redistributeProportionally(currentWidths, insertIndex, maxColumns, minWidth) {
|
|
85
115
|
if (currentWidths.length === 0 || !Number.isInteger(maxColumns) || maxColumns <= 0 || currentWidths.length >= maxColumns || insertIndex < 0 || insertIndex > currentWidths.length || !isValidWidth(minWidth) || currentWidths.some(function (width) {
|
|
86
116
|
return !isValidWidth(width);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.DeleteColumnDropdownItem = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _reactIntl = require("react-intl");
|
|
10
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
12
|
+
var _useCurrentLayoutColumn = require("./useCurrentLayoutColumn");
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
|
+
var DeleteColumnDropdownItem = exports.DeleteColumnDropdownItem = function DeleteColumnDropdownItem(_ref) {
|
|
15
|
+
var api = _ref.api;
|
|
16
|
+
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
17
|
+
formatMessage = _useIntl.formatMessage;
|
|
18
|
+
var currentColumn = (0, _useCurrentLayoutColumn.useCurrentLayoutColumn)(api);
|
|
19
|
+
var onClick = (0, _react.useCallback)(function () {
|
|
20
|
+
var _api$layout, _api$core;
|
|
21
|
+
var deleteCommand = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.deleteLayoutColumn;
|
|
22
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (props) {
|
|
23
|
+
var _api$layout2;
|
|
24
|
+
var tr = deleteCommand === null || deleteCommand === void 0 ? void 0 : deleteCommand(props);
|
|
25
|
+
if (!tr) {
|
|
26
|
+
return tr !== null && tr !== void 0 ? tr : null;
|
|
27
|
+
}
|
|
28
|
+
api === null || api === void 0 || (_api$layout2 = api.layout) === null || _api$layout2 === void 0 || _api$layout2.commands.toggleLayoutColumnMenu({
|
|
29
|
+
isOpen: false
|
|
30
|
+
})({
|
|
31
|
+
tr: tr
|
|
32
|
+
});
|
|
33
|
+
return tr;
|
|
34
|
+
});
|
|
35
|
+
}, [api]);
|
|
36
|
+
if (currentColumn === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
|
|
40
|
+
onClick: onClick
|
|
41
|
+
}, formatMessage(_messages.layoutMessages.deleteColumn));
|
|
42
|
+
};
|
|
@@ -10,6 +10,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
11
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
12
12
|
var _toolbarMenuContainer = require("@atlaskit/editor-toolbar/toolbar-menu-container");
|
|
13
|
+
var _DeleteColumnDropdownItem = require("./DeleteColumnDropdownItem");
|
|
13
14
|
var _DistributeColumnsDropdownItem = require("./DistributeColumnsDropdownItem");
|
|
14
15
|
var _InsertColumnDropdownItem = require("./InsertColumnDropdownItem");
|
|
15
16
|
var _keys = require("./keys");
|
|
@@ -56,6 +57,15 @@ var getLayoutColumnMenuComponents = exports.getLayoutColumnMenuComponents = func
|
|
|
56
57
|
parents: [_objectSpread(_objectSpread({}, _keys.LAYOUT_COLUMN_MENU_SECTION), {}, {
|
|
57
58
|
rank: _keys.LAYOUT_COLUMN_MENU_SECTION_RANK[_keys.DISTRIBUTE_COLUMNS_MENU_ITEM.key]
|
|
58
59
|
})]
|
|
60
|
+
}), _objectSpread(_objectSpread({}, _keys.DELETE_COLUMN_MENU_ITEM), {}, {
|
|
61
|
+
component: function component() {
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(_DeleteColumnDropdownItem.DeleteColumnDropdownItem, {
|
|
63
|
+
api: api
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
parents: [_objectSpread(_objectSpread({}, _keys.LAYOUT_COLUMN_MENU_SECTION), {}, {
|
|
67
|
+
rank: _keys.LAYOUT_COLUMN_MENU_SECTION_RANK[_keys.DELETE_COLUMN_MENU_ITEM.key]
|
|
68
|
+
})]
|
|
59
69
|
}), _objectSpread(_objectSpread({}, _keys.VERTICAL_ALIGN_MENU), {}, {
|
|
60
70
|
component: function component(_ref3) {
|
|
61
71
|
var children = _ref3.children;
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.VERTICAL_ALIGN_TOP_MENU_ITEM = exports.VERTICAL_ALIGN_MIDDLE_MENU_ITEM = exports.VERTICAL_ALIGN_MENU_SECTION_RANK = exports.VERTICAL_ALIGN_MENU_RANK = exports.VERTICAL_ALIGN_MENU = exports.VERTICAL_ALIGN_BOTTOM_MENU_ITEM = exports.LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION = exports.LAYOUT_COLUMN_MENU_SECTION_RANK = exports.LAYOUT_COLUMN_MENU_SECTION = exports.LAYOUT_COLUMN_MENU_RANK = exports.LAYOUT_COLUMN_MENU = exports.INSERT_COLUMN_RIGHT_MENU_ITEM = exports.INSERT_COLUMN_LEFT_MENU_ITEM = exports.DISTRIBUTE_COLUMNS_MENU_ITEM = void 0;
|
|
7
|
+
exports.VERTICAL_ALIGN_TOP_MENU_ITEM = exports.VERTICAL_ALIGN_MIDDLE_MENU_ITEM = exports.VERTICAL_ALIGN_MENU_SECTION_RANK = exports.VERTICAL_ALIGN_MENU_RANK = exports.VERTICAL_ALIGN_MENU = exports.VERTICAL_ALIGN_BOTTOM_MENU_ITEM = exports.LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION = exports.LAYOUT_COLUMN_MENU_SECTION_RANK = exports.LAYOUT_COLUMN_MENU_SECTION = exports.LAYOUT_COLUMN_MENU_RANK = exports.LAYOUT_COLUMN_MENU = exports.INSERT_COLUMN_RIGHT_MENU_ITEM = exports.INSERT_COLUMN_LEFT_MENU_ITEM = exports.DISTRIBUTE_COLUMNS_MENU_ITEM = exports.DELETE_COLUMN_MENU_ITEM = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
// --- Menu surface ---
|
|
10
10
|
|
|
@@ -58,9 +58,13 @@ var VERTICAL_ALIGN_BOTTOM_MENU_ITEM = exports.VERTICAL_ALIGN_BOTTOM_MENU_ITEM =
|
|
|
58
58
|
type: 'menu-item',
|
|
59
59
|
key: 'layout-column-menu-vertical-align-bottom-item'
|
|
60
60
|
};
|
|
61
|
+
var DELETE_COLUMN_MENU_ITEM = exports.DELETE_COLUMN_MENU_ITEM = {
|
|
62
|
+
type: 'menu-item',
|
|
63
|
+
key: 'layout-column-menu-delete-item'
|
|
64
|
+
};
|
|
61
65
|
|
|
62
66
|
// --- Item ranks within sections ---
|
|
63
67
|
|
|
64
|
-
var LAYOUT_COLUMN_MENU_SECTION_RANK = exports.LAYOUT_COLUMN_MENU_SECTION_RANK = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, VERTICAL_ALIGN_MENU.key, 100), INSERT_COLUMN_LEFT_MENU_ITEM.key, 200), INSERT_COLUMN_RIGHT_MENU_ITEM.key, 300), DISTRIBUTE_COLUMNS_MENU_ITEM.key, 400);
|
|
68
|
+
var LAYOUT_COLUMN_MENU_SECTION_RANK = exports.LAYOUT_COLUMN_MENU_SECTION_RANK = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, VERTICAL_ALIGN_MENU.key, 100), INSERT_COLUMN_LEFT_MENU_ITEM.key, 200), INSERT_COLUMN_RIGHT_MENU_ITEM.key, 300), DISTRIBUTE_COLUMNS_MENU_ITEM.key, 400), DELETE_COLUMN_MENU_ITEM.key, 500);
|
|
65
69
|
var VERTICAL_ALIGN_MENU_RANK = exports.VERTICAL_ALIGN_MENU_RANK = (0, _defineProperty2.default)({}, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION.key, 100);
|
|
66
70
|
var VERTICAL_ALIGN_MENU_SECTION_RANK = exports.VERTICAL_ALIGN_MENU_SECTION_RANK = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, VERTICAL_ALIGN_TOP_MENU_ITEM.key, 100), VERTICAL_ALIGN_MIDDLE_MENU_ITEM.key, 200), VERTICAL_ALIGN_BOTTOM_MENU_ITEM.key, 300);
|
|
@@ -8,9 +8,10 @@ import { IconFiveColumnLayout, IconFourColumnLayout, IconLayout, IconOneColumnLa
|
|
|
8
8
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
11
12
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
12
13
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
|
-
import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumn, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
14
|
+
import { createDefaultLayoutSection, createMultiColumnLayoutSection, deleteLayoutColumn, insertLayoutColumn, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
14
15
|
import { default as createLayoutPlugin } from './pm-plugins/main';
|
|
15
16
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
16
17
|
import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
|
|
@@ -147,25 +148,83 @@ export const layoutPlugin = ({
|
|
|
147
148
|
})(tr);
|
|
148
149
|
return tr;
|
|
149
150
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
151
|
+
if (editorExperiment('advanced_layouts', true)) {
|
|
152
|
+
const advancedSingleColumnOption = allowAdvancedSingleColumnLayout ? [{
|
|
153
|
+
id: 'onecolumnlayout',
|
|
154
|
+
title: formatMessage(layoutMessages.singleColumnAdvancedLayout),
|
|
155
|
+
description: formatMessage(messages.singleColumnsDescriptionAdvancedLayout),
|
|
156
|
+
keywords: ['layout', 'column', 'section', 'single column'],
|
|
157
|
+
priority: 1100,
|
|
158
|
+
icon: () => /*#__PURE__*/React.createElement(IconOneColumnLayout, null),
|
|
159
|
+
action(insert, state) {
|
|
160
|
+
const tr = insert(createMultiColumnLayoutSection(state, 1));
|
|
161
|
+
if (fg('platform_editor_column_count_analytics')) {
|
|
162
|
+
withInsertLayoutAnalytics(tr, 1);
|
|
163
|
+
} else {
|
|
164
|
+
withInsertLayoutAnalytics(tr);
|
|
165
|
+
}
|
|
166
|
+
selectIntoLayoutSection(tr);
|
|
167
|
+
return tr;
|
|
163
168
|
}
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
}] : [];
|
|
170
|
+
if (expValEquals('platform_editor_layout_typeahead_reorder', 'isEnabled', true)) {
|
|
171
|
+
const createAdvancedColumnLayoutOption = ({
|
|
172
|
+
columnCount,
|
|
173
|
+
descriptionColumnCount,
|
|
174
|
+
icon: Icon,
|
|
175
|
+
id,
|
|
176
|
+
keyword,
|
|
177
|
+
title
|
|
178
|
+
}) => ({
|
|
179
|
+
id,
|
|
180
|
+
title,
|
|
181
|
+
description: formatMessage(messages.columnsDescriptionAdvancedLayout, {
|
|
182
|
+
numberOfColumns: descriptionColumnCount
|
|
183
|
+
}),
|
|
184
|
+
keywords: ['layout', 'column', 'section', keyword],
|
|
185
|
+
priority: 1100,
|
|
186
|
+
icon: Icon,
|
|
187
|
+
action(insert, state) {
|
|
188
|
+
const tr = insert(createMultiColumnLayoutSection(state, columnCount));
|
|
189
|
+
if (fg('platform_editor_column_count_analytics')) {
|
|
190
|
+
withInsertLayoutAnalytics(tr, columnCount);
|
|
191
|
+
} else {
|
|
192
|
+
withInsertLayoutAnalytics(tr);
|
|
193
|
+
}
|
|
194
|
+
selectIntoLayoutSection(tr);
|
|
195
|
+
return tr;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return [createAdvancedColumnLayoutOption({
|
|
199
|
+
columnCount: 2,
|
|
200
|
+
descriptionColumnCount: 'two',
|
|
201
|
+
icon: () => /*#__PURE__*/React.createElement(IconTwoColumnLayout, null),
|
|
202
|
+
id: 'twocolumnslayout',
|
|
203
|
+
keyword: 'two column',
|
|
204
|
+
title: formatMessage(layoutMessages.twoColumnsAdvancedLayout)
|
|
205
|
+
}), ...advancedSingleColumnOption, createAdvancedColumnLayoutOption({
|
|
206
|
+
columnCount: 3,
|
|
207
|
+
descriptionColumnCount: 'three',
|
|
208
|
+
icon: () => /*#__PURE__*/React.createElement(IconThreeColumnLayout, null),
|
|
209
|
+
id: 'threecolumnslayout',
|
|
210
|
+
keyword: 'three column',
|
|
211
|
+
title: formatMessage(layoutMessages.threeColumnsAdvancedLayout)
|
|
212
|
+
}), createAdvancedColumnLayoutOption({
|
|
213
|
+
columnCount: 4,
|
|
214
|
+
descriptionColumnCount: 'four',
|
|
215
|
+
icon: () => /*#__PURE__*/React.createElement(IconFourColumnLayout, null),
|
|
216
|
+
id: 'fourcolumnslayout',
|
|
217
|
+
keyword: 'four column',
|
|
218
|
+
title: formatMessage(layoutMessages.fourColumns)
|
|
219
|
+
}), createAdvancedColumnLayoutOption({
|
|
220
|
+
columnCount: 5,
|
|
221
|
+
descriptionColumnCount: 'five',
|
|
222
|
+
icon: () => /*#__PURE__*/React.createElement(IconFiveColumnLayout, null),
|
|
223
|
+
id: 'fivecolumnslayout',
|
|
224
|
+
keyword: 'five column',
|
|
225
|
+
title: formatMessage(layoutMessages.fiveColumns)
|
|
226
|
+
})];
|
|
166
227
|
}
|
|
167
|
-
}] : [];
|
|
168
|
-
if (editorExperiment('advanced_layouts', true)) {
|
|
169
228
|
return [...advancedSingleColumnOption, {
|
|
170
229
|
id: 'twocolumnslayout',
|
|
171
230
|
title: formatMessage(layoutMessages.twoColumnsAdvancedLayout),
|
|
@@ -290,9 +349,13 @@ export const layoutPlugin = ({
|
|
|
290
349
|
return pluginKey.getState(editorState);
|
|
291
350
|
},
|
|
292
351
|
commands: {
|
|
293
|
-
|
|
352
|
+
deleteLayoutColumn: props => {
|
|
294
353
|
var _api$analytics4;
|
|
295
|
-
return
|
|
354
|
+
return deleteLayoutColumn(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(props);
|
|
355
|
+
},
|
|
356
|
+
insertLayoutColumn: side => {
|
|
357
|
+
var _api$analytics5;
|
|
358
|
+
return insertLayoutColumn(side, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
296
359
|
},
|
|
297
360
|
setLayoutColumnValign,
|
|
298
361
|
toggleLayoutColumnMenu
|
|
@@ -9,7 +9,7 @@ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equ
|
|
|
9
9
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
10
10
|
import { EVEN_DISTRIBUTED_COL_WIDTHS, MAX_LAYOUT_COLUMNS, MAX_STANDARD_LAYOUT_COLUMNS, MIN_LAYOUT_COLUMN_WIDTH_PERCENT } from './consts';
|
|
11
11
|
import { pluginKey } from './plugin-key';
|
|
12
|
-
import { redistributeProportionally } from './utils/redistribute-proportionally';
|
|
12
|
+
import { redistributeAfterDeletion, redistributeProportionally } from './utils/redistribute-proportionally';
|
|
13
13
|
export const ONE_COL_LAYOUTS = ['single'];
|
|
14
14
|
export const TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
|
|
15
15
|
export const THREE_COL_LAYOUTS = ['three_equal', 'three_with_sidebars'];
|
|
@@ -659,4 +659,58 @@ export const toggleLayoutColumnMenu = ({
|
|
|
659
659
|
});
|
|
660
660
|
tr.setMeta('scrollIntoView', false);
|
|
661
661
|
return tr;
|
|
662
|
+
};
|
|
663
|
+
export const deleteLayoutColumn = editorAnalyticsAPI => ({
|
|
664
|
+
tr
|
|
665
|
+
}) => {
|
|
666
|
+
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
const selectedColumn = getSelectedLayoutColumnInSection(tr);
|
|
670
|
+
if (!selectedColumn) {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
const {
|
|
674
|
+
layoutSectionNode,
|
|
675
|
+
layoutSectionPos,
|
|
676
|
+
selectedColumnIndex
|
|
677
|
+
} = selectedColumn;
|
|
678
|
+
const emitDeleteColumnAnalytics = columnCount => {
|
|
679
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
680
|
+
action: ACTION.DELETED,
|
|
681
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
682
|
+
actionSubjectId: ACTION_SUBJECT_ID.LAYOUT_COLUMN,
|
|
683
|
+
attributes: {
|
|
684
|
+
columnCount,
|
|
685
|
+
inputMethod: INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
686
|
+
selectedIndex: selectedColumnIndex
|
|
687
|
+
},
|
|
688
|
+
eventType: EVENT_TYPE.TRACK
|
|
689
|
+
})(tr);
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// If only one column remains, remove the entire layoutSection
|
|
693
|
+
if (layoutSectionNode.childCount === 1) {
|
|
694
|
+
tr.delete(layoutSectionPos, layoutSectionPos + layoutSectionNode.nodeSize);
|
|
695
|
+
emitDeleteColumnAnalytics(0);
|
|
696
|
+
tr.setMeta('scrollIntoView', false);
|
|
697
|
+
return tr;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Build new column list without the selected column
|
|
701
|
+
const remainingColumns = [];
|
|
702
|
+
layoutSectionNode.forEach((column, _offset, index) => {
|
|
703
|
+
if (index !== selectedColumnIndex) {
|
|
704
|
+
remainingColumns.push(column);
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
// Redistribute widths proportionally among remaining columns using shared utility
|
|
709
|
+
const existingWidths = mapChildren(layoutSectionNode, column => column.attrs.width);
|
|
710
|
+
const redistributed = redistributeAfterDeletion(existingWidths, selectedColumnIndex, MIN_LAYOUT_COLUMN_WIDTH_PERCENT);
|
|
711
|
+
const updatedLayoutSectionNode = layoutSectionNode.copy(Fragment.fromArray(remainingColumns));
|
|
712
|
+
tr.replaceWith(layoutSectionPos + 1, layoutSectionPos + layoutSectionNode.nodeSize - 1, columnWidth(updatedLayoutSectionNode, tr.doc.type.schema, redistributed));
|
|
713
|
+
emitDeleteColumnAnalytics(redistributed.length);
|
|
714
|
+
tr.setMeta('scrollIntoView', false);
|
|
715
|
+
return tr;
|
|
662
716
|
};
|
|
@@ -61,6 +61,30 @@ const redistributeWithMinimumWidth = ({
|
|
|
61
61
|
});
|
|
62
62
|
return widths;
|
|
63
63
|
};
|
|
64
|
+
export const redistributeAfterDeletion = (currentWidths, removeIndex, minWidth) => {
|
|
65
|
+
if (currentWidths.length === 0 || removeIndex < 0 || removeIndex >= currentWidths.length || !isValidWidth(minWidth)) {
|
|
66
|
+
return currentWidths;
|
|
67
|
+
}
|
|
68
|
+
if (currentWidths.some(width => !isValidWidth(width))) {
|
|
69
|
+
return currentWidths.filter((_, i) => i !== removeIndex);
|
|
70
|
+
}
|
|
71
|
+
const remainingWidths = currentWidths.filter((_, i) => i !== removeIndex);
|
|
72
|
+
if (remainingWidths.length === 0) {
|
|
73
|
+
return remainingWidths;
|
|
74
|
+
}
|
|
75
|
+
const currentTotalWidth = sumWidths(currentWidths);
|
|
76
|
+
const targetTotalWidth = Math.round(currentTotalWidth) === 100 ? 100 : currentTotalWidth;
|
|
77
|
+
const redistributed = redistributeWithMinimumWidth({
|
|
78
|
+
weights: remainingWidths,
|
|
79
|
+
totalWidth: targetTotalWidth,
|
|
80
|
+
minWidth
|
|
81
|
+
});
|
|
82
|
+
if (!redistributed) {
|
|
83
|
+
const equalWidth = roundLayoutColumnWidth(targetTotalWidth / remainingWidths.length);
|
|
84
|
+
return normaliseWidthsTotal(Array(remainingWidths.length).fill(equalWidth), targetTotalWidth, minWidth);
|
|
85
|
+
}
|
|
86
|
+
return normaliseWidthsTotal(redistributed, targetTotalWidth, minWidth);
|
|
87
|
+
};
|
|
64
88
|
export const redistributeProportionally = (currentWidths, insertIndex, maxColumns, minWidth) => {
|
|
65
89
|
if (currentWidths.length === 0 || !Number.isInteger(maxColumns) || maxColumns <= 0 || currentWidths.length >= maxColumns || insertIndex < 0 || insertIndex > currentWidths.length || !isValidWidth(minWidth) || currentWidths.some(width => !isValidWidth(width))) {
|
|
66
90
|
return currentWidths;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { useCurrentLayoutColumn } from './useCurrentLayoutColumn';
|
|
6
|
+
const DeleteColumnDropdownItem = ({
|
|
7
|
+
api
|
|
8
|
+
}) => {
|
|
9
|
+
const {
|
|
10
|
+
formatMessage
|
|
11
|
+
} = useIntl();
|
|
12
|
+
const currentColumn = useCurrentLayoutColumn(api);
|
|
13
|
+
const onClick = useCallback(() => {
|
|
14
|
+
var _api$layout, _api$core;
|
|
15
|
+
const deleteCommand = api === null || api === void 0 ? void 0 : (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.deleteLayoutColumn;
|
|
16
|
+
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(props => {
|
|
17
|
+
var _api$layout2;
|
|
18
|
+
const tr = deleteCommand === null || deleteCommand === void 0 ? void 0 : deleteCommand(props);
|
|
19
|
+
if (!tr) {
|
|
20
|
+
return tr !== null && tr !== void 0 ? tr : null;
|
|
21
|
+
}
|
|
22
|
+
api === null || api === void 0 ? void 0 : (_api$layout2 = api.layout) === null || _api$layout2 === void 0 ? void 0 : _api$layout2.commands.toggleLayoutColumnMenu({
|
|
23
|
+
isOpen: false
|
|
24
|
+
})({
|
|
25
|
+
tr
|
|
26
|
+
});
|
|
27
|
+
return tr;
|
|
28
|
+
});
|
|
29
|
+
}, [api]);
|
|
30
|
+
if (currentColumn === undefined) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
34
|
+
onClick: onClick
|
|
35
|
+
}, formatMessage(layoutMessages.deleteColumn));
|
|
36
|
+
};
|
|
37
|
+
export { DeleteColumnDropdownItem };
|
|
@@ -2,9 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
3
3
|
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
4
4
|
import { ToolbarMenuContainer } from '@atlaskit/editor-toolbar/toolbar-menu-container';
|
|
5
|
+
import { DeleteColumnDropdownItem } from './DeleteColumnDropdownItem';
|
|
5
6
|
import { createDistributeColumnsDropdownItem } from './DistributeColumnsDropdownItem';
|
|
6
7
|
import { InsertColumnDropdownItem } from './InsertColumnDropdownItem';
|
|
7
|
-
import { DISTRIBUTE_COLUMNS_MENU_ITEM, INSERT_COLUMN_LEFT_MENU_ITEM, INSERT_COLUMN_RIGHT_MENU_ITEM, LAYOUT_COLUMN_MENU, LAYOUT_COLUMN_MENU_RANK, LAYOUT_COLUMN_MENU_SECTION, LAYOUT_COLUMN_MENU_SECTION_RANK, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION, VERTICAL_ALIGN_BOTTOM_MENU_ITEM, VERTICAL_ALIGN_MENU, VERTICAL_ALIGN_MENU_RANK, VERTICAL_ALIGN_MENU_SECTION_RANK, VERTICAL_ALIGN_MIDDLE_MENU_ITEM, VERTICAL_ALIGN_TOP_MENU_ITEM } from './keys';
|
|
8
|
+
import { DELETE_COLUMN_MENU_ITEM, DISTRIBUTE_COLUMNS_MENU_ITEM, INSERT_COLUMN_LEFT_MENU_ITEM, INSERT_COLUMN_RIGHT_MENU_ITEM, LAYOUT_COLUMN_MENU, LAYOUT_COLUMN_MENU_RANK, LAYOUT_COLUMN_MENU_SECTION, LAYOUT_COLUMN_MENU_SECTION_RANK, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION, VERTICAL_ALIGN_BOTTOM_MENU_ITEM, VERTICAL_ALIGN_MENU, VERTICAL_ALIGN_MENU_RANK, VERTICAL_ALIGN_MENU_SECTION_RANK, VERTICAL_ALIGN_MIDDLE_MENU_ITEM, VERTICAL_ALIGN_TOP_MENU_ITEM } from './keys';
|
|
8
9
|
import { VerticalAlignDropdownItem } from './VerticalAlignDropdownItem';
|
|
9
10
|
import { VerticalAlignNestedMenu } from './VerticalAlignNestedMenu';
|
|
10
11
|
export const LAYOUT_COLUMN_MENU_FALLBACKS = {
|
|
@@ -51,6 +52,15 @@ export const getLayoutColumnMenuComponents = ({
|
|
|
51
52
|
...LAYOUT_COLUMN_MENU_SECTION,
|
|
52
53
|
rank: LAYOUT_COLUMN_MENU_SECTION_RANK[DISTRIBUTE_COLUMNS_MENU_ITEM.key]
|
|
53
54
|
}]
|
|
55
|
+
}, {
|
|
56
|
+
...DELETE_COLUMN_MENU_ITEM,
|
|
57
|
+
component: () => /*#__PURE__*/React.createElement(DeleteColumnDropdownItem, {
|
|
58
|
+
api: api
|
|
59
|
+
}),
|
|
60
|
+
parents: [{
|
|
61
|
+
...LAYOUT_COLUMN_MENU_SECTION,
|
|
62
|
+
rank: LAYOUT_COLUMN_MENU_SECTION_RANK[DELETE_COLUMN_MENU_ITEM.key]
|
|
63
|
+
}]
|
|
54
64
|
}, {
|
|
55
65
|
...VERTICAL_ALIGN_MENU,
|
|
56
66
|
component: ({
|
|
@@ -52,6 +52,10 @@ export const VERTICAL_ALIGN_BOTTOM_MENU_ITEM = {
|
|
|
52
52
|
type: 'menu-item',
|
|
53
53
|
key: 'layout-column-menu-vertical-align-bottom-item'
|
|
54
54
|
};
|
|
55
|
+
export const DELETE_COLUMN_MENU_ITEM = {
|
|
56
|
+
type: 'menu-item',
|
|
57
|
+
key: 'layout-column-menu-delete-item'
|
|
58
|
+
};
|
|
55
59
|
|
|
56
60
|
// --- Item ranks within sections ---
|
|
57
61
|
|
|
@@ -59,7 +63,8 @@ export const LAYOUT_COLUMN_MENU_SECTION_RANK = {
|
|
|
59
63
|
[VERTICAL_ALIGN_MENU.key]: 100,
|
|
60
64
|
[INSERT_COLUMN_LEFT_MENU_ITEM.key]: 200,
|
|
61
65
|
[INSERT_COLUMN_RIGHT_MENU_ITEM.key]: 300,
|
|
62
|
-
[DISTRIBUTE_COLUMNS_MENU_ITEM.key]: 400
|
|
66
|
+
[DISTRIBUTE_COLUMNS_MENU_ITEM.key]: 400,
|
|
67
|
+
[DELETE_COLUMN_MENU_ITEM.key]: 500
|
|
63
68
|
};
|
|
64
69
|
export const VERTICAL_ALIGN_MENU_RANK = {
|
|
65
70
|
[LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION.key]: 100
|
package/dist/esm/layoutPlugin.js
CHANGED
|
@@ -8,9 +8,10 @@ import { IconFiveColumnLayout, IconFourColumnLayout, IconLayout, IconOneColumnLa
|
|
|
8
8
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
11
12
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
12
13
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
|
-
import { createDefaultLayoutSection, createMultiColumnLayoutSection, insertLayoutColumn as _insertLayoutColumn, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
14
|
+
import { createDefaultLayoutSection, createMultiColumnLayoutSection, deleteLayoutColumn as _deleteLayoutColumn, insertLayoutColumn as _insertLayoutColumn, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
14
15
|
import { default as createLayoutPlugin } from './pm-plugins/main';
|
|
15
16
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
16
17
|
import { default as createLayoutResizingPlugin } from './pm-plugins/resizing';
|
|
@@ -148,27 +149,94 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
148
149
|
})(tr);
|
|
149
150
|
return tr;
|
|
150
151
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
if (editorExperiment('advanced_layouts', true)) {
|
|
153
|
+
var advancedSingleColumnOption = allowAdvancedSingleColumnLayout ? [{
|
|
154
|
+
id: 'onecolumnlayout',
|
|
155
|
+
title: formatMessage(layoutMessages.singleColumnAdvancedLayout),
|
|
156
|
+
description: formatMessage(messages.singleColumnsDescriptionAdvancedLayout),
|
|
157
|
+
keywords: ['layout', 'column', 'section', 'single column'],
|
|
158
|
+
priority: 1100,
|
|
159
|
+
icon: function icon() {
|
|
160
|
+
return /*#__PURE__*/React.createElement(IconOneColumnLayout, null);
|
|
161
|
+
},
|
|
162
|
+
action: function action(insert, state) {
|
|
163
|
+
var tr = insert(createMultiColumnLayoutSection(state, 1));
|
|
164
|
+
if (fg('platform_editor_column_count_analytics')) {
|
|
165
|
+
withInsertLayoutAnalytics(tr, 1);
|
|
166
|
+
} else {
|
|
167
|
+
withInsertLayoutAnalytics(tr);
|
|
168
|
+
}
|
|
169
|
+
selectIntoLayoutSection(tr);
|
|
170
|
+
return tr;
|
|
166
171
|
}
|
|
167
|
-
|
|
168
|
-
|
|
172
|
+
}] : [];
|
|
173
|
+
if (expValEquals('platform_editor_layout_typeahead_reorder', 'isEnabled', true)) {
|
|
174
|
+
var createAdvancedColumnLayoutOption = function createAdvancedColumnLayoutOption(_ref4) {
|
|
175
|
+
var columnCount = _ref4.columnCount,
|
|
176
|
+
descriptionColumnCount = _ref4.descriptionColumnCount,
|
|
177
|
+
Icon = _ref4.icon,
|
|
178
|
+
id = _ref4.id,
|
|
179
|
+
keyword = _ref4.keyword,
|
|
180
|
+
title = _ref4.title;
|
|
181
|
+
return {
|
|
182
|
+
id: id,
|
|
183
|
+
title: title,
|
|
184
|
+
description: formatMessage(messages.columnsDescriptionAdvancedLayout, {
|
|
185
|
+
numberOfColumns: descriptionColumnCount
|
|
186
|
+
}),
|
|
187
|
+
keywords: ['layout', 'column', 'section', keyword],
|
|
188
|
+
priority: 1100,
|
|
189
|
+
icon: Icon,
|
|
190
|
+
action: function action(insert, state) {
|
|
191
|
+
var tr = insert(createMultiColumnLayoutSection(state, columnCount));
|
|
192
|
+
if (fg('platform_editor_column_count_analytics')) {
|
|
193
|
+
withInsertLayoutAnalytics(tr, columnCount);
|
|
194
|
+
} else {
|
|
195
|
+
withInsertLayoutAnalytics(tr);
|
|
196
|
+
}
|
|
197
|
+
selectIntoLayoutSection(tr);
|
|
198
|
+
return tr;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
return [createAdvancedColumnLayoutOption({
|
|
203
|
+
columnCount: 2,
|
|
204
|
+
descriptionColumnCount: 'two',
|
|
205
|
+
icon: function icon() {
|
|
206
|
+
return /*#__PURE__*/React.createElement(IconTwoColumnLayout, null);
|
|
207
|
+
},
|
|
208
|
+
id: 'twocolumnslayout',
|
|
209
|
+
keyword: 'two column',
|
|
210
|
+
title: formatMessage(layoutMessages.twoColumnsAdvancedLayout)
|
|
211
|
+
})].concat(advancedSingleColumnOption, [createAdvancedColumnLayoutOption({
|
|
212
|
+
columnCount: 3,
|
|
213
|
+
descriptionColumnCount: 'three',
|
|
214
|
+
icon: function icon() {
|
|
215
|
+
return /*#__PURE__*/React.createElement(IconThreeColumnLayout, null);
|
|
216
|
+
},
|
|
217
|
+
id: 'threecolumnslayout',
|
|
218
|
+
keyword: 'three column',
|
|
219
|
+
title: formatMessage(layoutMessages.threeColumnsAdvancedLayout)
|
|
220
|
+
}), createAdvancedColumnLayoutOption({
|
|
221
|
+
columnCount: 4,
|
|
222
|
+
descriptionColumnCount: 'four',
|
|
223
|
+
icon: function icon() {
|
|
224
|
+
return /*#__PURE__*/React.createElement(IconFourColumnLayout, null);
|
|
225
|
+
},
|
|
226
|
+
id: 'fourcolumnslayout',
|
|
227
|
+
keyword: 'four column',
|
|
228
|
+
title: formatMessage(layoutMessages.fourColumns)
|
|
229
|
+
}), createAdvancedColumnLayoutOption({
|
|
230
|
+
columnCount: 5,
|
|
231
|
+
descriptionColumnCount: 'five',
|
|
232
|
+
icon: function icon() {
|
|
233
|
+
return /*#__PURE__*/React.createElement(IconFiveColumnLayout, null);
|
|
234
|
+
},
|
|
235
|
+
id: 'fivecolumnslayout',
|
|
236
|
+
keyword: 'five column',
|
|
237
|
+
title: formatMessage(layoutMessages.fiveColumns)
|
|
238
|
+
})]);
|
|
169
239
|
}
|
|
170
|
-
}] : [];
|
|
171
|
-
if (editorExperiment('advanced_layouts', true)) {
|
|
172
240
|
return [].concat(advancedSingleColumnOption, [{
|
|
173
241
|
id: 'twocolumnslayout',
|
|
174
242
|
title: formatMessage(layoutMessages.twoColumnsAdvancedLayout),
|
|
@@ -282,11 +350,11 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
282
350
|
}
|
|
283
351
|
}
|
|
284
352
|
},
|
|
285
|
-
contentComponent: function contentComponent(
|
|
286
|
-
var editorView =
|
|
287
|
-
popupsMountPoint =
|
|
288
|
-
popupsBoundariesElement =
|
|
289
|
-
popupsScrollableElement =
|
|
353
|
+
contentComponent: function contentComponent(_ref5) {
|
|
354
|
+
var editorView = _ref5.editorView,
|
|
355
|
+
popupsMountPoint = _ref5.popupsMountPoint,
|
|
356
|
+
popupsBoundariesElement = _ref5.popupsBoundariesElement,
|
|
357
|
+
popupsScrollableElement = _ref5.popupsScrollableElement;
|
|
290
358
|
return /*#__PURE__*/React.createElement(React.Fragment, null, editorExperiment('advanced_layouts', true) ? /*#__PURE__*/React.createElement(GlobalStylesWrapper, null) : null, expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true) && editorView ? /*#__PURE__*/React.createElement(LayoutColumnMenu, {
|
|
291
359
|
api: api,
|
|
292
360
|
editorView: editorView,
|
|
@@ -302,9 +370,13 @@ export var layoutPlugin = function layoutPlugin(_ref) {
|
|
|
302
370
|
return pluginKey.getState(editorState);
|
|
303
371
|
},
|
|
304
372
|
commands: {
|
|
305
|
-
|
|
373
|
+
deleteLayoutColumn: function deleteLayoutColumn(props) {
|
|
306
374
|
var _api$analytics4;
|
|
307
|
-
return
|
|
375
|
+
return _deleteLayoutColumn(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(props);
|
|
376
|
+
},
|
|
377
|
+
insertLayoutColumn: function insertLayoutColumn(side) {
|
|
378
|
+
var _api$analytics5;
|
|
379
|
+
return _insertLayoutColumn(side, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
308
380
|
},
|
|
309
381
|
setLayoutColumnValign: setLayoutColumnValign,
|
|
310
382
|
toggleLayoutColumnMenu: toggleLayoutColumnMenu
|
|
@@ -12,7 +12,7 @@ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equ
|
|
|
12
12
|
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
|
-
import { redistributeProportionally } from './utils/redistribute-proportionally';
|
|
15
|
+
import { redistributeAfterDeletion, redistributeProportionally } from './utils/redistribute-proportionally';
|
|
16
16
|
export var ONE_COL_LAYOUTS = ['single'];
|
|
17
17
|
export var TWO_COL_LAYOUTS = ['two_equal', 'two_left_sidebar', 'two_right_sidebar'];
|
|
18
18
|
export var THREE_COL_LAYOUTS = ['three_equal', 'three_with_sidebars'];
|
|
@@ -668,4 +668,59 @@ export var toggleLayoutColumnMenu = function toggleLayoutColumnMenu(_ref7) {
|
|
|
668
668
|
tr.setMeta('scrollIntoView', false);
|
|
669
669
|
return tr;
|
|
670
670
|
};
|
|
671
|
+
};
|
|
672
|
+
export var deleteLayoutColumn = function deleteLayoutColumn(editorAnalyticsAPI) {
|
|
673
|
+
return function (_ref9) {
|
|
674
|
+
var tr = _ref9.tr;
|
|
675
|
+
if (!expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
var selectedColumn = getSelectedLayoutColumnInSection(tr);
|
|
679
|
+
if (!selectedColumn) {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
var layoutSectionNode = selectedColumn.layoutSectionNode,
|
|
683
|
+
layoutSectionPos = selectedColumn.layoutSectionPos,
|
|
684
|
+
selectedColumnIndex = selectedColumn.selectedColumnIndex;
|
|
685
|
+
var emitDeleteColumnAnalytics = function emitDeleteColumnAnalytics(columnCount) {
|
|
686
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
687
|
+
action: ACTION.DELETED,
|
|
688
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
689
|
+
actionSubjectId: ACTION_SUBJECT_ID.LAYOUT_COLUMN,
|
|
690
|
+
attributes: {
|
|
691
|
+
columnCount: columnCount,
|
|
692
|
+
inputMethod: INPUT_METHOD.LAYOUT_COLUMN_MENU,
|
|
693
|
+
selectedIndex: selectedColumnIndex
|
|
694
|
+
},
|
|
695
|
+
eventType: EVENT_TYPE.TRACK
|
|
696
|
+
})(tr);
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
// If only one column remains, remove the entire layoutSection
|
|
700
|
+
if (layoutSectionNode.childCount === 1) {
|
|
701
|
+
tr.delete(layoutSectionPos, layoutSectionPos + layoutSectionNode.nodeSize);
|
|
702
|
+
emitDeleteColumnAnalytics(0);
|
|
703
|
+
tr.setMeta('scrollIntoView', false);
|
|
704
|
+
return tr;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Build new column list without the selected column
|
|
708
|
+
var remainingColumns = [];
|
|
709
|
+
layoutSectionNode.forEach(function (column, _offset, index) {
|
|
710
|
+
if (index !== selectedColumnIndex) {
|
|
711
|
+
remainingColumns.push(column);
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// Redistribute widths proportionally among remaining columns using shared utility
|
|
716
|
+
var existingWidths = mapChildren(layoutSectionNode, function (column) {
|
|
717
|
+
return column.attrs.width;
|
|
718
|
+
});
|
|
719
|
+
var redistributed = redistributeAfterDeletion(existingWidths, selectedColumnIndex, MIN_LAYOUT_COLUMN_WIDTH_PERCENT);
|
|
720
|
+
var updatedLayoutSectionNode = layoutSectionNode.copy(Fragment.fromArray(remainingColumns));
|
|
721
|
+
tr.replaceWith(layoutSectionPos + 1, layoutSectionPos + layoutSectionNode.nodeSize - 1, columnWidth(updatedLayoutSectionNode, tr.doc.type.schema, redistributed));
|
|
722
|
+
emitDeleteColumnAnalytics(redistributed.length);
|
|
723
|
+
tr.setMeta('scrollIntoView', false);
|
|
724
|
+
return tr;
|
|
725
|
+
};
|
|
671
726
|
};
|
|
@@ -74,6 +74,36 @@ var redistributeWithMinimumWidth = function redistributeWithMinimumWidth(_ref) {
|
|
|
74
74
|
});
|
|
75
75
|
return widths;
|
|
76
76
|
};
|
|
77
|
+
export var redistributeAfterDeletion = function redistributeAfterDeletion(currentWidths, removeIndex, minWidth) {
|
|
78
|
+
if (currentWidths.length === 0 || removeIndex < 0 || removeIndex >= currentWidths.length || !isValidWidth(minWidth)) {
|
|
79
|
+
return currentWidths;
|
|
80
|
+
}
|
|
81
|
+
if (currentWidths.some(function (width) {
|
|
82
|
+
return !isValidWidth(width);
|
|
83
|
+
})) {
|
|
84
|
+
return currentWidths.filter(function (_, i) {
|
|
85
|
+
return i !== removeIndex;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
var remainingWidths = currentWidths.filter(function (_, i) {
|
|
89
|
+
return i !== removeIndex;
|
|
90
|
+
});
|
|
91
|
+
if (remainingWidths.length === 0) {
|
|
92
|
+
return remainingWidths;
|
|
93
|
+
}
|
|
94
|
+
var currentTotalWidth = sumWidths(currentWidths);
|
|
95
|
+
var targetTotalWidth = Math.round(currentTotalWidth) === 100 ? 100 : currentTotalWidth;
|
|
96
|
+
var redistributed = redistributeWithMinimumWidth({
|
|
97
|
+
weights: remainingWidths,
|
|
98
|
+
totalWidth: targetTotalWidth,
|
|
99
|
+
minWidth: minWidth
|
|
100
|
+
});
|
|
101
|
+
if (!redistributed) {
|
|
102
|
+
var equalWidth = roundLayoutColumnWidth(targetTotalWidth / remainingWidths.length);
|
|
103
|
+
return normaliseWidthsTotal(Array(remainingWidths.length).fill(equalWidth), targetTotalWidth, minWidth);
|
|
104
|
+
}
|
|
105
|
+
return normaliseWidthsTotal(redistributed, targetTotalWidth, minWidth);
|
|
106
|
+
};
|
|
77
107
|
export var redistributeProportionally = function redistributeProportionally(currentWidths, insertIndex, maxColumns, minWidth) {
|
|
78
108
|
if (currentWidths.length === 0 || !Number.isInteger(maxColumns) || maxColumns <= 0 || currentWidths.length >= maxColumns || insertIndex < 0 || insertIndex > currentWidths.length || !isValidWidth(minWidth) || currentWidths.some(function (width) {
|
|
79
109
|
return !isValidWidth(width);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
|
|
5
|
+
import { useCurrentLayoutColumn } from './useCurrentLayoutColumn';
|
|
6
|
+
var DeleteColumnDropdownItem = function DeleteColumnDropdownItem(_ref) {
|
|
7
|
+
var api = _ref.api;
|
|
8
|
+
var _useIntl = useIntl(),
|
|
9
|
+
formatMessage = _useIntl.formatMessage;
|
|
10
|
+
var currentColumn = useCurrentLayoutColumn(api);
|
|
11
|
+
var onClick = useCallback(function () {
|
|
12
|
+
var _api$layout, _api$core;
|
|
13
|
+
var deleteCommand = api === null || api === void 0 || (_api$layout = api.layout) === null || _api$layout === void 0 ? void 0 : _api$layout.commands.deleteLayoutColumn;
|
|
14
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (props) {
|
|
15
|
+
var _api$layout2;
|
|
16
|
+
var tr = deleteCommand === null || deleteCommand === void 0 ? void 0 : deleteCommand(props);
|
|
17
|
+
if (!tr) {
|
|
18
|
+
return tr !== null && tr !== void 0 ? tr : null;
|
|
19
|
+
}
|
|
20
|
+
api === null || api === void 0 || (_api$layout2 = api.layout) === null || _api$layout2 === void 0 || _api$layout2.commands.toggleLayoutColumnMenu({
|
|
21
|
+
isOpen: false
|
|
22
|
+
})({
|
|
23
|
+
tr: tr
|
|
24
|
+
});
|
|
25
|
+
return tr;
|
|
26
|
+
});
|
|
27
|
+
}, [api]);
|
|
28
|
+
if (currentColumn === undefined) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
|
|
32
|
+
onClick: onClick
|
|
33
|
+
}, formatMessage(layoutMessages.deleteColumn));
|
|
34
|
+
};
|
|
35
|
+
export { DeleteColumnDropdownItem };
|
|
@@ -5,9 +5,10 @@ import React from 'react';
|
|
|
5
5
|
import { layoutMessages } from '@atlaskit/editor-common/messages';
|
|
6
6
|
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
7
7
|
import { ToolbarMenuContainer } from '@atlaskit/editor-toolbar/toolbar-menu-container';
|
|
8
|
+
import { DeleteColumnDropdownItem } from './DeleteColumnDropdownItem';
|
|
8
9
|
import { createDistributeColumnsDropdownItem } from './DistributeColumnsDropdownItem';
|
|
9
10
|
import { InsertColumnDropdownItem } from './InsertColumnDropdownItem';
|
|
10
|
-
import { DISTRIBUTE_COLUMNS_MENU_ITEM, INSERT_COLUMN_LEFT_MENU_ITEM, INSERT_COLUMN_RIGHT_MENU_ITEM, LAYOUT_COLUMN_MENU, LAYOUT_COLUMN_MENU_RANK, LAYOUT_COLUMN_MENU_SECTION, LAYOUT_COLUMN_MENU_SECTION_RANK, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION, VERTICAL_ALIGN_BOTTOM_MENU_ITEM, VERTICAL_ALIGN_MENU, VERTICAL_ALIGN_MENU_RANK, VERTICAL_ALIGN_MENU_SECTION_RANK, VERTICAL_ALIGN_MIDDLE_MENU_ITEM, VERTICAL_ALIGN_TOP_MENU_ITEM } from './keys';
|
|
11
|
+
import { DELETE_COLUMN_MENU_ITEM, DISTRIBUTE_COLUMNS_MENU_ITEM, INSERT_COLUMN_LEFT_MENU_ITEM, INSERT_COLUMN_RIGHT_MENU_ITEM, LAYOUT_COLUMN_MENU, LAYOUT_COLUMN_MENU_RANK, LAYOUT_COLUMN_MENU_SECTION, LAYOUT_COLUMN_MENU_SECTION_RANK, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION, VERTICAL_ALIGN_BOTTOM_MENU_ITEM, VERTICAL_ALIGN_MENU, VERTICAL_ALIGN_MENU_RANK, VERTICAL_ALIGN_MENU_SECTION_RANK, VERTICAL_ALIGN_MIDDLE_MENU_ITEM, VERTICAL_ALIGN_TOP_MENU_ITEM } from './keys';
|
|
11
12
|
import { VerticalAlignDropdownItem } from './VerticalAlignDropdownItem';
|
|
12
13
|
import { VerticalAlignNestedMenu } from './VerticalAlignNestedMenu';
|
|
13
14
|
export var LAYOUT_COLUMN_MENU_FALLBACKS = {
|
|
@@ -49,6 +50,15 @@ export var getLayoutColumnMenuComponents = function getLayoutColumnMenuComponent
|
|
|
49
50
|
parents: [_objectSpread(_objectSpread({}, LAYOUT_COLUMN_MENU_SECTION), {}, {
|
|
50
51
|
rank: LAYOUT_COLUMN_MENU_SECTION_RANK[DISTRIBUTE_COLUMNS_MENU_ITEM.key]
|
|
51
52
|
})]
|
|
53
|
+
}), _objectSpread(_objectSpread({}, DELETE_COLUMN_MENU_ITEM), {}, {
|
|
54
|
+
component: function component() {
|
|
55
|
+
return /*#__PURE__*/React.createElement(DeleteColumnDropdownItem, {
|
|
56
|
+
api: api
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
parents: [_objectSpread(_objectSpread({}, LAYOUT_COLUMN_MENU_SECTION), {}, {
|
|
60
|
+
rank: LAYOUT_COLUMN_MENU_SECTION_RANK[DELETE_COLUMN_MENU_ITEM.key]
|
|
61
|
+
})]
|
|
52
62
|
}), _objectSpread(_objectSpread({}, VERTICAL_ALIGN_MENU), {}, {
|
|
53
63
|
component: function component(_ref3) {
|
|
54
64
|
var children = _ref3.children;
|
|
@@ -51,9 +51,13 @@ export var VERTICAL_ALIGN_BOTTOM_MENU_ITEM = {
|
|
|
51
51
|
type: 'menu-item',
|
|
52
52
|
key: 'layout-column-menu-vertical-align-bottom-item'
|
|
53
53
|
};
|
|
54
|
+
export var DELETE_COLUMN_MENU_ITEM = {
|
|
55
|
+
type: 'menu-item',
|
|
56
|
+
key: 'layout-column-menu-delete-item'
|
|
57
|
+
};
|
|
54
58
|
|
|
55
59
|
// --- Item ranks within sections ---
|
|
56
60
|
|
|
57
|
-
export var LAYOUT_COLUMN_MENU_SECTION_RANK = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VERTICAL_ALIGN_MENU.key, 100), INSERT_COLUMN_LEFT_MENU_ITEM.key, 200), INSERT_COLUMN_RIGHT_MENU_ITEM.key, 300), DISTRIBUTE_COLUMNS_MENU_ITEM.key, 400);
|
|
61
|
+
export var LAYOUT_COLUMN_MENU_SECTION_RANK = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, VERTICAL_ALIGN_MENU.key, 100), INSERT_COLUMN_LEFT_MENU_ITEM.key, 200), INSERT_COLUMN_RIGHT_MENU_ITEM.key, 300), DISTRIBUTE_COLUMNS_MENU_ITEM.key, 400), DELETE_COLUMN_MENU_ITEM.key, 500);
|
|
58
62
|
export var VERTICAL_ALIGN_MENU_RANK = _defineProperty({}, LAYOUT_COLUMN_VERTICAL_ALIGN_MENU_SECTION.key, 100);
|
|
59
63
|
export var VERTICAL_ALIGN_MENU_SECTION_RANK = _defineProperty(_defineProperty(_defineProperty({}, VERTICAL_ALIGN_TOP_MENU_ITEM.key, 100), VERTICAL_ALIGN_MIDDLE_MENU_ITEM.key, 200), VERTICAL_ALIGN_BOTTOM_MENU_ITEM.key, 300);
|
|
@@ -9,7 +9,7 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
|
9
9
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
10
10
|
import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
|
|
11
11
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
12
|
-
import type { InsertLayoutColumnSide, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
12
|
+
import type { deleteLayoutColumn, InsertLayoutColumnSide, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
13
13
|
import type { LayoutState } from './pm-plugins/types';
|
|
14
14
|
import type { LayoutPluginOptions } from './types';
|
|
15
15
|
export type LayoutPluginDependencies = [
|
|
@@ -29,6 +29,7 @@ export type LayoutPlugin = NextEditorPlugin<'layout', {
|
|
|
29
29
|
insertLayoutColumns: ReturnType<typeof insertLayoutColumnsWithAnalytics>;
|
|
30
30
|
};
|
|
31
31
|
commands: {
|
|
32
|
+
deleteLayoutColumn: ReturnType<typeof deleteLayoutColumn>;
|
|
32
33
|
insertLayoutColumn: (side: InsertLayoutColumnSide) => EditorCommand;
|
|
33
34
|
setLayoutColumnValign: typeof setLayoutColumnValign;
|
|
34
35
|
toggleLayoutColumnMenu: typeof toggleLayoutColumnMenu;
|
|
@@ -37,3 +37,4 @@ export declare const setLayoutColumnValign: (valign: Valign) => EditorCommand;
|
|
|
37
37
|
export declare const toggleLayoutColumnMenu: ({ isOpen }: {
|
|
38
38
|
isOpen?: boolean;
|
|
39
39
|
}) => EditorCommand;
|
|
40
|
+
export declare const deleteLayoutColumn: (editorAnalyticsAPI?: EditorAnalyticsAPI) => EditorCommand;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { LayoutPlugin } from '../../layoutPluginType';
|
|
4
|
+
type DeleteColumnDropdownItemProps = {
|
|
5
|
+
api: ExtractInjectionAPI<LayoutPlugin> | undefined;
|
|
6
|
+
};
|
|
7
|
+
declare const DeleteColumnDropdownItem: ({ api, }: DeleteColumnDropdownItemProps) => React.JSX.Element | null;
|
|
8
|
+
export { DeleteColumnDropdownItem };
|
|
@@ -10,6 +10,7 @@ export declare const DISTRIBUTE_COLUMNS_MENU_ITEM: MenuItemType;
|
|
|
10
10
|
export declare const VERTICAL_ALIGN_TOP_MENU_ITEM: MenuItemType;
|
|
11
11
|
export declare const VERTICAL_ALIGN_MIDDLE_MENU_ITEM: MenuItemType;
|
|
12
12
|
export declare const VERTICAL_ALIGN_BOTTOM_MENU_ITEM: MenuItemType;
|
|
13
|
+
export declare const DELETE_COLUMN_MENU_ITEM: MenuItemType;
|
|
13
14
|
export declare const LAYOUT_COLUMN_MENU_SECTION_RANK: Record<string, number>;
|
|
14
15
|
export declare const VERTICAL_ALIGN_MENU_RANK: Record<string, number>;
|
|
15
16
|
export declare const VERTICAL_ALIGN_MENU_SECTION_RANK: Record<string, number>;
|
|
@@ -9,7 +9,7 @@ import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
|
9
9
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
10
10
|
import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
|
|
11
11
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
12
|
-
import type { InsertLayoutColumnSide, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
12
|
+
import type { deleteLayoutColumn, InsertLayoutColumnSide, insertLayoutColumnsWithAnalytics, setLayoutColumnValign, toggleLayoutColumnMenu } from './pm-plugins/actions';
|
|
13
13
|
import type { LayoutState } from './pm-plugins/types';
|
|
14
14
|
import type { LayoutPluginOptions } from './types';
|
|
15
15
|
export type LayoutPluginDependencies = [
|
|
@@ -29,6 +29,7 @@ export type LayoutPlugin = NextEditorPlugin<'layout', {
|
|
|
29
29
|
insertLayoutColumns: ReturnType<typeof insertLayoutColumnsWithAnalytics>;
|
|
30
30
|
};
|
|
31
31
|
commands: {
|
|
32
|
+
deleteLayoutColumn: ReturnType<typeof deleteLayoutColumn>;
|
|
32
33
|
insertLayoutColumn: (side: InsertLayoutColumnSide) => EditorCommand;
|
|
33
34
|
setLayoutColumnValign: typeof setLayoutColumnValign;
|
|
34
35
|
toggleLayoutColumnMenu: typeof toggleLayoutColumnMenu;
|
|
@@ -37,3 +37,4 @@ export declare const setLayoutColumnValign: (valign: Valign) => EditorCommand;
|
|
|
37
37
|
export declare const toggleLayoutColumnMenu: ({ isOpen }: {
|
|
38
38
|
isOpen?: boolean;
|
|
39
39
|
}) => EditorCommand;
|
|
40
|
+
export declare const deleteLayoutColumn: (editorAnalyticsAPI?: EditorAnalyticsAPI) => EditorCommand;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { LayoutPlugin } from '../../layoutPluginType';
|
|
4
|
+
type DeleteColumnDropdownItemProps = {
|
|
5
|
+
api: ExtractInjectionAPI<LayoutPlugin> | undefined;
|
|
6
|
+
};
|
|
7
|
+
declare const DeleteColumnDropdownItem: ({ api, }: DeleteColumnDropdownItemProps) => React.JSX.Element | null;
|
|
8
|
+
export { DeleteColumnDropdownItem };
|
|
@@ -10,6 +10,7 @@ export declare const DISTRIBUTE_COLUMNS_MENU_ITEM: MenuItemType;
|
|
|
10
10
|
export declare const VERTICAL_ALIGN_TOP_MENU_ITEM: MenuItemType;
|
|
11
11
|
export declare const VERTICAL_ALIGN_MIDDLE_MENU_ITEM: MenuItemType;
|
|
12
12
|
export declare const VERTICAL_ALIGN_BOTTOM_MENU_ITEM: MenuItemType;
|
|
13
|
+
export declare const DELETE_COLUMN_MENU_ITEM: MenuItemType;
|
|
13
14
|
export declare const LAYOUT_COLUMN_MENU_SECTION_RANK: Record<string, number>;
|
|
14
15
|
export declare const VERTICAL_ALIGN_MENU_RANK: Record<string, number>;
|
|
15
16
|
export declare const VERTICAL_ALIGN_MENU_SECTION_RANK: Record<string, number>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-layout",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.0",
|
|
4
4
|
"description": "Layout plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,19 +43,19 @@
|
|
|
43
43
|
"@atlaskit/editor-plugin-width": "^11.1.0",
|
|
44
44
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
45
45
|
"@atlaskit/editor-shared-styles": "^3.11.0",
|
|
46
|
-
"@atlaskit/editor-toolbar": "^1.
|
|
46
|
+
"@atlaskit/editor-toolbar": "^1.7.0",
|
|
47
47
|
"@atlaskit/editor-ui-control-model": "^1.2.0",
|
|
48
48
|
"@atlaskit/icon": "^35.0.0",
|
|
49
49
|
"@atlaskit/icon-lab": "^6.9.0",
|
|
50
50
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^82.
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^82.5.0",
|
|
52
52
|
"@atlaskit/tokens": "^13.0.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@emotion/react": "^11.7.1",
|
|
55
55
|
"bind-event-listener": "^3.0.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@atlaskit/editor-common": "^114.
|
|
58
|
+
"@atlaskit/editor-common": "^114.42.0",
|
|
59
59
|
"react": "^18.2.0",
|
|
60
60
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
61
61
|
},
|
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
|
+
"react": "^18.2.0",
|
|
118
119
|
"react-intl": "^6.6.2"
|
|
119
120
|
}
|
|
120
121
|
}
|