@atlaskit/editor-plugin-table 7.15.0 → 7.16.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 +23 -0
- package/dist/cjs/commands/misc.js +15 -1
- package/dist/cjs/commands-with-analytics.js +25 -2
- package/dist/cjs/plugin.js +1 -2
- package/dist/cjs/toolbar.js +21 -19
- package/dist/cjs/utils/alignment.js +13 -0
- package/dist/es2019/commands/misc.js +15 -1
- package/dist/es2019/commands-with-analytics.js +22 -2
- package/dist/es2019/plugin.js +2 -3
- package/dist/es2019/toolbar.js +19 -19
- package/dist/es2019/utils/alignment.js +5 -0
- package/dist/esm/commands/misc.js +14 -0
- package/dist/esm/commands-with-analytics.js +25 -2
- package/dist/esm/plugin.js +2 -3
- package/dist/esm/toolbar.js +21 -19
- package/dist/esm/utils/alignment.js +7 -0
- package/dist/types/commands/misc.d.ts +3 -1
- package/dist/types/commands-with-analytics.d.ts +3 -1
- package/dist/types/toolbar.d.ts +11 -2
- package/dist/types/types.d.ts +1 -0
- package/dist/types/utils/alignment.d.ts +7 -0
- package/dist/types-ts4.5/commands/misc.d.ts +3 -1
- package/dist/types-ts4.5/commands-with-analytics.d.ts +3 -1
- package/dist/types-ts4.5/toolbar.d.ts +11 -2
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/utils/alignment.d.ts +7 -0
- package/package.json +5 -8
- package/src/commands/misc.ts +28 -6
- package/src/commands-with-analytics.ts +38 -1
- package/src/plugin.tsx +2 -14
- package/src/toolbar.tsx +47 -27
- package/src/types.ts +2 -0
- package/src/utils/alignment.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.16.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#101355](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/101355)
|
|
8
|
+
[`040f4ffe7af0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/040f4ffe7af0) -
|
|
9
|
+
Add analytic event to table alignment command
|
|
10
|
+
- [#101524](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/101524)
|
|
11
|
+
[`4821570088e6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4821570088e6) -
|
|
12
|
+
ED-23362 Bump ADF schema to version 36.8.1 and add support for adf validation and transformation
|
|
13
|
+
|
|
14
|
+
## 7.16.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [#100692](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100692)
|
|
19
|
+
[`76587b8092dc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/76587b8092dc) -
|
|
20
|
+
[ux] ED-22924 Table - Created and hooked command to alignment toolbar buttons
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
|
|
3
26
|
## 7.15.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
|
@@ -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.updateWidthToWidest = exports.updateResizeHandleDecorations = exports.triggerUnlessTableHeader = exports.transformSliceToRemoveColumnsWidths = exports.transformSliceToAddTableHeaders = exports.transformSliceRemoveCellBackgroundColor = exports.showInsertRowButton = exports.showInsertColumnButton = exports.setTableRef = exports.setMultipleCellAttrs = exports.setEditorFocus = exports.setCellAttr = exports.selectRows = exports.selectRow = exports.selectColumns = exports.selectColumn = exports.removeResizeHandleDecorations = exports.moveCursorBackward = exports.isInsideFirstCellOfRowOrColumn = exports.hideInsertColumnOrRowButton = exports.getTableSelectionType = exports.getTableElementMoveTypeBySlice = exports.deleteTableIfSelected = exports.deleteTable = exports.countCellsInSlice = exports.convertFirstRowToHeader = exports.autoSizeTable = exports.addResizeHandleDecorations = exports.addBoldInEmptyHeaderCells = void 0;
|
|
7
|
+
exports.updateWidthToWidest = exports.updateResizeHandleDecorations = exports.triggerUnlessTableHeader = exports.transformSliceToRemoveColumnsWidths = exports.transformSliceToAddTableHeaders = exports.transformSliceRemoveCellBackgroundColor = exports.showInsertRowButton = exports.showInsertColumnButton = exports.setTableRef = exports.setTableAlignment = exports.setMultipleCellAttrs = exports.setEditorFocus = exports.setCellAttr = exports.selectRows = exports.selectRow = exports.selectColumns = exports.selectColumn = exports.removeResizeHandleDecorations = exports.moveCursorBackward = exports.isInsideFirstCellOfRowOrColumn = exports.hideInsertColumnOrRowButton = exports.getTableSelectionType = exports.getTableElementMoveTypeBySlice = exports.deleteTableIfSelected = exports.deleteTable = exports.countCellsInSlice = exports.convertFirstRowToHeader = exports.autoSizeTable = exports.addResizeHandleDecorations = exports.addBoldInEmptyHeaderCells = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
@@ -586,4 +586,18 @@ var updateWidthToWidest = exports.updateWidthToWidest = function updateWidthToWi
|
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
588
|
});
|
|
589
|
+
};
|
|
590
|
+
var setTableAlignment = exports.setTableAlignment = function setTableAlignment(newAlignment) {
|
|
591
|
+
return function (_ref2) {
|
|
592
|
+
var tr = _ref2.tr;
|
|
593
|
+
var tableObject = (0, _utils2.findTable)(tr.selection);
|
|
594
|
+
if (!tableObject) {
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
|
|
598
|
+
layout: newAlignment
|
|
599
|
+
});
|
|
600
|
+
tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
|
|
601
|
+
return tr;
|
|
602
|
+
};
|
|
589
603
|
};
|
|
@@ -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.wrapTableInExpandWithAnalytics = exports.toggleTableLockWithAnalytics = exports.toggleTableLayoutWithAnalytics = exports.toggleNumberColumnWithAnalytics = exports.toggleHeaderRowWithAnalytics = exports.toggleHeaderColumnWithAnalytics = exports.splitCellWithAnalytics = exports.sortColumnWithAnalytics = exports.setColorWithAnalytics = exports.mergeCellsWithAnalytics = exports.insertRowWithAnalytics = exports.insertColumnWithAnalytics = exports.emptyMultipleCellsWithAnalytics = exports.distributeColumnsWidthsWithAnalytics = exports.deleteTableWithAnalytics = exports.deleteTableIfSelectedWithAnalytics = exports.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = exports.deleteRowsWithAnalytics = exports.deleteColumnsWithAnalytics = exports.changeColumnWidthByStepWithAnalytics = exports.addRowAroundSelection = void 0;
|
|
7
|
+
exports.wrapTableInExpandWithAnalytics = exports.toggleTableLockWithAnalytics = exports.toggleTableLayoutWithAnalytics = exports.toggleNumberColumnWithAnalytics = exports.toggleHeaderRowWithAnalytics = exports.toggleHeaderColumnWithAnalytics = exports.splitCellWithAnalytics = exports.sortColumnWithAnalytics = exports.setTableAlignmentWithAnalytics = exports.setColorWithAnalytics = exports.mergeCellsWithAnalytics = exports.insertRowWithAnalytics = exports.insertColumnWithAnalytics = exports.emptyMultipleCellsWithAnalytics = exports.distributeColumnsWidthsWithAnalytics = exports.deleteTableWithAnalytics = exports.deleteTableIfSelectedWithAnalytics = exports.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut = exports.deleteRowsWithAnalytics = exports.deleteColumnsWithAnalytics = exports.changeColumnWidthByStepWithAnalytics = exports.addRowAroundSelection = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
10
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -537,4 +537,27 @@ var toggleTableLockWithAnalytics = exports.toggleTableLockWithAnalytics = functi
|
|
|
537
537
|
})(editorAnalyticsAPI)((0, _preset.editorCommandToPMCommand)(_displayMode.setTableDisplayMode));
|
|
538
538
|
};
|
|
539
539
|
};
|
|
540
|
-
|
|
540
|
+
var setTableAlignmentWithAnalytics = exports.setTableAlignmentWithAnalytics = function setTableAlignmentWithAnalytics(editorAnalyticsAPI) {
|
|
541
|
+
return function (newAlignment, previousAlignment, inputMethod) {
|
|
542
|
+
return (0, _analytics2.withEditorAnalyticsAPI)(function (state) {
|
|
543
|
+
var _getSelectedTableInfo14 = (0, _utils2.getSelectedTableInfo)(state.selection),
|
|
544
|
+
table = _getSelectedTableInfo14.table,
|
|
545
|
+
totalRowCount = _getSelectedTableInfo14.totalRowCount,
|
|
546
|
+
totalColumnCount = _getSelectedTableInfo14.totalColumnCount;
|
|
547
|
+
return {
|
|
548
|
+
action: _analytics.TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
549
|
+
actionSubject: _analytics.ACTION_SUBJECT.TABLE,
|
|
550
|
+
actionSubjectId: null,
|
|
551
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
552
|
+
attributes: {
|
|
553
|
+
tableWidth: table === null || table === void 0 ? void 0 : table.node.attrs.width,
|
|
554
|
+
newAlignment: newAlignment,
|
|
555
|
+
previousAlignment: previousAlignment === 'center' || previousAlignment === 'align-start' ? previousAlignment : null,
|
|
556
|
+
totalRowCount: totalRowCount,
|
|
557
|
+
totalColumnCount: totalColumnCount,
|
|
558
|
+
inputMethod: inputMethod
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
})(editorAnalyticsAPI)((0, _preset.editorCommandToPMCommand)((0, _misc.setTableAlignment)(newAlignment)));
|
|
562
|
+
};
|
|
563
|
+
};
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -120,10 +120,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
120
120
|
insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
121
121
|
},
|
|
122
122
|
nodes: function nodes() {
|
|
123
|
-
var tableNode = options !== null && options !== void 0 && options.isTableScalingEnabled && (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.preserve-widths-with-lock-button') ? _adfSchema.tableStage0 : _adfSchema.table;
|
|
124
123
|
return [{
|
|
125
124
|
name: 'table',
|
|
126
|
-
node:
|
|
125
|
+
node: _adfSchema.table
|
|
127
126
|
}, {
|
|
128
127
|
name: 'tableHeader',
|
|
129
128
|
node: _adfSchema.tableHeader
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getLockBtnConfig = exports.getDistributeConfig = exports.getClosestSelectionRect = exports.getClosestSelectionOrTableRect = exports.getAlignmentOptionsConfig = void 0;
|
|
8
|
+
exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getSelectedAlignmentIcon = exports.getLockBtnConfig = exports.getDistributeConfig = exports.getClosestSelectionRect = exports.getClosestSelectionOrTableRect = exports.getAlignmentOptionsConfig = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _react = require("@emotion/react");
|
|
@@ -37,6 +37,7 @@ var _types = require("./types");
|
|
|
37
37
|
var _FloatingAlignmentButtons = require("./ui/FloatingAlignmentButtons/FloatingAlignmentButtons");
|
|
38
38
|
var _icons = require("./ui/icons");
|
|
39
39
|
var _utils4 = require("./utils");
|
|
40
|
+
var _alignment = require("./utils/alignment");
|
|
40
41
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
41
42
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
42
43
|
/** @jsx jsx */
|
|
@@ -329,7 +330,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
329
330
|
var nodeType = state.schema.nodes.table;
|
|
330
331
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
331
332
|
var alignmentMenu;
|
|
332
|
-
|
|
333
|
+
var isNested = pluginState.tablePos && (0, _utils4.isTableNested)(state, pluginState.tablePos);
|
|
334
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
333
335
|
var cellItems;
|
|
334
336
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
335
337
|
var columnSettingsItems;
|
|
@@ -593,8 +595,12 @@ var highlightColumnsHandler = function highlightColumnsHandler(state, dispatch)
|
|
|
593
595
|
}
|
|
594
596
|
return false;
|
|
595
597
|
};
|
|
596
|
-
var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function getAlignmentOptionsConfig(
|
|
598
|
+
var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6, editorAnalyticsAPI) {
|
|
597
599
|
var formatMessage = _ref6.formatMessage;
|
|
600
|
+
var tableObject = (0, _utils3.findTable)(editorState.selection);
|
|
601
|
+
if (!tableObject) {
|
|
602
|
+
return [];
|
|
603
|
+
}
|
|
598
604
|
var alignmentIcons = [{
|
|
599
605
|
id: 'editor.table.alignLeft',
|
|
600
606
|
value: 'align-start',
|
|
@@ -614,17 +620,17 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
614
620
|
var id = alignmentIcon.id,
|
|
615
621
|
value = alignmentIcon.value,
|
|
616
622
|
icon = alignmentIcon.icon;
|
|
623
|
+
var currentLayout = tableObject.node.attrs.layout;
|
|
617
624
|
return {
|
|
618
625
|
id: id,
|
|
619
626
|
type: 'button',
|
|
620
627
|
icon: icon,
|
|
621
628
|
title: formatMessage(layoutToMessages[value]),
|
|
622
|
-
selected:
|
|
623
|
-
|
|
624
|
-
onClick: makeAlignment()
|
|
629
|
+
selected: (0, _alignment.normaliseAlignment)(currentLayout) === value,
|
|
630
|
+
onClick: (0, _commandsWithAnalytics.setTableAlignmentWithAnalytics)(editorAnalyticsAPI)(value, currentLayout, _analytics.INPUT_METHOD.FLOATING_TB)
|
|
625
631
|
};
|
|
626
632
|
});
|
|
627
|
-
var
|
|
633
|
+
var alignmentItemOptions = {
|
|
628
634
|
render: function render(props) {
|
|
629
635
|
return (0, _react.jsx)(_FloatingAlignmentButtons.FloatingAlignmentButtons, (0, _extends2.default)({
|
|
630
636
|
alignmentButtons: alignmentButtons
|
|
@@ -633,24 +639,20 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
633
639
|
width: 60,
|
|
634
640
|
height: 32
|
|
635
641
|
};
|
|
642
|
+
var selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
636
643
|
var alignmentToolbarItem = [{
|
|
637
644
|
id: 'table-layout',
|
|
638
645
|
testId: 'table-layout-dropdown',
|
|
639
646
|
type: 'dropdown',
|
|
640
|
-
options:
|
|
647
|
+
options: alignmentItemOptions,
|
|
641
648
|
title: formatMessage(_messages.tableMessages.tableAlignmentOptions),
|
|
642
|
-
|
|
643
|
-
icon: _alignImageCenter.default // TODO - get the correct icon based on the selected layout attr
|
|
649
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
644
650
|
}];
|
|
645
651
|
return alignmentToolbarItem;
|
|
646
652
|
};
|
|
647
|
-
var
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
// TODO Add alignment logic here
|
|
654
|
-
return true;
|
|
655
|
-
};
|
|
653
|
+
var getSelectedAlignmentIcon = exports.getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
654
|
+
var selectedAlignment = selectedNode.attrs.layout;
|
|
655
|
+
return alignmentIcons.find(function (icon) {
|
|
656
|
+
return icon.value === (0, _alignment.normaliseAlignment)(selectedAlignment);
|
|
657
|
+
});
|
|
656
658
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normaliseAlignment = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
9
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
10
|
+
*/
|
|
11
|
+
var normaliseAlignment = exports.normaliseAlignment = function normaliseAlignment(layout) {
|
|
12
|
+
return layout === 'center' || layout === 'align-start' ? layout : 'center';
|
|
13
|
+
};
|
|
@@ -549,4 +549,18 @@ export const updateWidthToWidest = widthToWidest => createCommand(state => {
|
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
};
|
|
552
|
-
});
|
|
552
|
+
});
|
|
553
|
+
export const setTableAlignment = newAlignment => ({
|
|
554
|
+
tr
|
|
555
|
+
}) => {
|
|
556
|
+
const tableObject = findTable(tr.selection);
|
|
557
|
+
if (!tableObject) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
const nextTableAttrs = {
|
|
561
|
+
...tableObject.node.attrs,
|
|
562
|
+
layout: newAlignment
|
|
563
|
+
};
|
|
564
|
+
tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
|
|
565
|
+
return tr;
|
|
566
|
+
};
|
|
@@ -9,7 +9,7 @@ import { changeColumnWidthByStep } from './commands/column-resize';
|
|
|
9
9
|
import { deleteColumnsCommand } from './commands/delete';
|
|
10
10
|
import { setTableDisplayMode } from './commands/display-mode';
|
|
11
11
|
import { insertColumn, insertRow } from './commands/insert';
|
|
12
|
-
import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs } from './commands/misc';
|
|
12
|
+
import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs, setTableAlignment } from './commands/misc';
|
|
13
13
|
import { sortByColumn } from './commands/sort';
|
|
14
14
|
import { splitCell } from './commands/split-cell';
|
|
15
15
|
import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
|
|
@@ -490,4 +490,24 @@ export const toggleTableLockWithAnalytics = editorAnalyticsAPI => (displayMode,
|
|
|
490
490
|
eventType: EVENT_TYPE.TRACK
|
|
491
491
|
};
|
|
492
492
|
})(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
|
|
493
|
-
|
|
493
|
+
export const setTableAlignmentWithAnalytics = editorAnalyticsAPI => (newAlignment, previousAlignment, inputMethod) => withEditorAnalyticsAPI(state => {
|
|
494
|
+
const {
|
|
495
|
+
table,
|
|
496
|
+
totalRowCount,
|
|
497
|
+
totalColumnCount
|
|
498
|
+
} = getSelectedTableInfo(state.selection);
|
|
499
|
+
return {
|
|
500
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
501
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
502
|
+
actionSubjectId: null,
|
|
503
|
+
eventType: EVENT_TYPE.TRACK,
|
|
504
|
+
attributes: {
|
|
505
|
+
tableWidth: table === null || table === void 0 ? void 0 : table.node.attrs.width,
|
|
506
|
+
newAlignment,
|
|
507
|
+
previousAlignment: previousAlignment === 'center' || previousAlignment === 'align-start' ? previousAlignment : null,
|
|
508
|
+
totalRowCount,
|
|
509
|
+
totalColumnCount,
|
|
510
|
+
inputMethod
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
})(editorAnalyticsAPI)(editorCommandToPMCommand(setTableAlignment(newAlignment)));
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { table, tableCell, tableHeader, tableRow
|
|
2
|
+
import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
5
5
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
@@ -110,10 +110,9 @@ const tablesPlugin = ({
|
|
|
110
110
|
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
111
111
|
},
|
|
112
112
|
nodes() {
|
|
113
|
-
const tableNode = options !== null && options !== void 0 && options.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') ? tableStage0 : table;
|
|
114
113
|
return [{
|
|
115
114
|
name: 'table',
|
|
116
|
-
node:
|
|
115
|
+
node: table
|
|
117
116
|
}, {
|
|
118
117
|
name: 'tableHeader',
|
|
119
118
|
node: tableHeader
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -19,7 +19,7 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
|
19
19
|
import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
|
|
20
20
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
21
21
|
import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
|
|
22
|
-
import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
|
|
22
|
+
import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, setTableAlignmentWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
|
|
23
23
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
24
24
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
25
25
|
import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizing/utils/resize-state';
|
|
@@ -29,6 +29,7 @@ import { TableCssClassName } from './types';
|
|
|
29
29
|
import { FloatingAlignmentButtons } from './ui/FloatingAlignmentButtons/FloatingAlignmentButtons';
|
|
30
30
|
import { DisplayModeIcon } from './ui/icons';
|
|
31
31
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
|
|
32
|
+
import { normaliseAlignment } from './utils/alignment';
|
|
32
33
|
export const getToolbarMenuConfig = (config, state, {
|
|
33
34
|
formatMessage
|
|
34
35
|
}, editorAnalyticsAPI) => {
|
|
@@ -315,7 +316,8 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
315
316
|
const nodeType = state.schema.nodes.table;
|
|
316
317
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
317
318
|
let alignmentMenu;
|
|
318
|
-
|
|
319
|
+
const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
320
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
319
321
|
let cellItems;
|
|
320
322
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
321
323
|
let columnSettingsItems;
|
|
@@ -560,9 +562,13 @@ const highlightColumnsHandler = (state, dispatch) => {
|
|
|
560
562
|
}
|
|
561
563
|
return false;
|
|
562
564
|
};
|
|
563
|
-
export const getAlignmentOptionsConfig = (
|
|
565
|
+
export const getAlignmentOptionsConfig = (editorState, {
|
|
564
566
|
formatMessage
|
|
565
567
|
}, editorAnalyticsAPI) => {
|
|
568
|
+
const tableObject = findTable(editorState.selection);
|
|
569
|
+
if (!tableObject) {
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
566
572
|
const alignmentIcons = [{
|
|
567
573
|
id: 'editor.table.alignLeft',
|
|
568
574
|
value: 'align-start',
|
|
@@ -584,17 +590,17 @@ export const getAlignmentOptionsConfig = (state, {
|
|
|
584
590
|
value,
|
|
585
591
|
icon
|
|
586
592
|
} = alignmentIcon;
|
|
593
|
+
const currentLayout = tableObject.node.attrs.layout;
|
|
587
594
|
return {
|
|
588
595
|
id: id,
|
|
589
596
|
type: 'button',
|
|
590
597
|
icon: icon,
|
|
591
598
|
title: formatMessage(layoutToMessages[value]),
|
|
592
|
-
selected:
|
|
593
|
-
|
|
594
|
-
onClick: makeAlignment()
|
|
599
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
600
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(value, currentLayout, INPUT_METHOD.FLOATING_TB)
|
|
595
601
|
};
|
|
596
602
|
});
|
|
597
|
-
const
|
|
603
|
+
const alignmentItemOptions = {
|
|
598
604
|
render: props => {
|
|
599
605
|
return jsx(FloatingAlignmentButtons, _extends({
|
|
600
606
|
alignmentButtons: alignmentButtons
|
|
@@ -603,24 +609,18 @@ export const getAlignmentOptionsConfig = (state, {
|
|
|
603
609
|
width: 60,
|
|
604
610
|
height: 32
|
|
605
611
|
};
|
|
612
|
+
const selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
606
613
|
const alignmentToolbarItem = [{
|
|
607
614
|
id: 'table-layout',
|
|
608
615
|
testId: 'table-layout-dropdown',
|
|
609
616
|
type: 'dropdown',
|
|
610
|
-
options:
|
|
617
|
+
options: alignmentItemOptions,
|
|
611
618
|
title: formatMessage(messages.tableAlignmentOptions),
|
|
612
|
-
|
|
613
|
-
icon: EditorAlignImageCenter // TODO - get the correct icon based on the selected layout attr
|
|
619
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
614
620
|
}];
|
|
615
621
|
return alignmentToolbarItem;
|
|
616
622
|
};
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
if (!tableObject || !dispatch) {
|
|
621
|
-
return false;
|
|
622
|
-
}
|
|
623
|
-
// TODO Add alignment logic here
|
|
624
|
-
return true;
|
|
625
|
-
};
|
|
623
|
+
export const getSelectedAlignmentIcon = (alignmentIcons, selectedNode) => {
|
|
624
|
+
const selectedAlignment = selectedNode.attrs.layout;
|
|
625
|
+
return alignmentIcons.find(icon => icon.value === normaliseAlignment(selectedAlignment));
|
|
626
626
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
3
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
4
|
+
*/
|
|
5
|
+
export const normaliseAlignment = layout => layout === 'center' || layout === 'align-start' ? layout : 'center';
|
|
@@ -579,4 +579,18 @@ export var updateWidthToWidest = function updateWidthToWidest(widthToWidest) {
|
|
|
579
579
|
}
|
|
580
580
|
};
|
|
581
581
|
});
|
|
582
|
+
};
|
|
583
|
+
export var setTableAlignment = function setTableAlignment(newAlignment) {
|
|
584
|
+
return function (_ref2) {
|
|
585
|
+
var tr = _ref2.tr;
|
|
586
|
+
var tableObject = findTable(tr.selection);
|
|
587
|
+
if (!tableObject) {
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
590
|
+
var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
|
|
591
|
+
layout: newAlignment
|
|
592
|
+
});
|
|
593
|
+
tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
|
|
594
|
+
return tr;
|
|
595
|
+
};
|
|
582
596
|
};
|
|
@@ -12,7 +12,7 @@ import { changeColumnWidthByStep } from './commands/column-resize';
|
|
|
12
12
|
import { deleteColumnsCommand } from './commands/delete';
|
|
13
13
|
import { setTableDisplayMode } from './commands/display-mode';
|
|
14
14
|
import { insertColumn, insertRow } from './commands/insert';
|
|
15
|
-
import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs } from './commands/misc';
|
|
15
|
+
import { deleteTable, deleteTableIfSelected, getTableSelectionType, setMultipleCellAttrs, setTableAlignment } from './commands/misc';
|
|
16
16
|
import { sortByColumn } from './commands/sort';
|
|
17
17
|
import { splitCell } from './commands/split-cell';
|
|
18
18
|
import { getNextLayout, toggleHeaderColumn, toggleHeaderRow, toggleNumberColumn, toggleTableLayout } from './commands/toggle';
|
|
@@ -530,4 +530,27 @@ export var toggleTableLockWithAnalytics = function toggleTableLockWithAnalytics(
|
|
|
530
530
|
})(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
|
|
531
531
|
};
|
|
532
532
|
};
|
|
533
|
-
|
|
533
|
+
export var setTableAlignmentWithAnalytics = function setTableAlignmentWithAnalytics(editorAnalyticsAPI) {
|
|
534
|
+
return function (newAlignment, previousAlignment, inputMethod) {
|
|
535
|
+
return withEditorAnalyticsAPI(function (state) {
|
|
536
|
+
var _getSelectedTableInfo14 = getSelectedTableInfo(state.selection),
|
|
537
|
+
table = _getSelectedTableInfo14.table,
|
|
538
|
+
totalRowCount = _getSelectedTableInfo14.totalRowCount,
|
|
539
|
+
totalColumnCount = _getSelectedTableInfo14.totalColumnCount;
|
|
540
|
+
return {
|
|
541
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
542
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
543
|
+
actionSubjectId: null,
|
|
544
|
+
eventType: EVENT_TYPE.TRACK,
|
|
545
|
+
attributes: {
|
|
546
|
+
tableWidth: table === null || table === void 0 ? void 0 : table.node.attrs.width,
|
|
547
|
+
newAlignment: newAlignment,
|
|
548
|
+
previousAlignment: previousAlignment === 'center' || previousAlignment === 'align-start' ? previousAlignment : null,
|
|
549
|
+
totalRowCount: totalRowCount,
|
|
550
|
+
totalColumnCount: totalColumnCount,
|
|
551
|
+
inputMethod: inputMethod
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
})(editorAnalyticsAPI)(editorCommandToPMCommand(setTableAlignment(newAlignment)));
|
|
555
|
+
};
|
|
556
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { table, tableCell, tableHeader, tableRow
|
|
2
|
+
import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
|
|
5
5
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
@@ -113,10 +113,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
113
113
|
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
114
114
|
},
|
|
115
115
|
nodes: function nodes() {
|
|
116
|
-
var tableNode = options !== null && options !== void 0 && options.isTableScalingEnabled && getBooleanFF('platform.editor.table.preserve-widths-with-lock-button') ? tableStage0 : table;
|
|
117
116
|
return [{
|
|
118
117
|
name: 'table',
|
|
119
|
-
node:
|
|
118
|
+
node: table
|
|
120
119
|
}, {
|
|
121
120
|
name: 'tableHeader',
|
|
122
121
|
node: tableHeader
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -20,7 +20,7 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
|
20
20
|
import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
|
|
21
21
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
22
22
|
import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
|
|
23
|
-
import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
|
|
23
|
+
import { deleteColumnsWithAnalytics, deleteRowsWithAnalytics, deleteTableWithAnalytics, distributeColumnsWidthsWithAnalytics, emptyMultipleCellsWithAnalytics, insertColumnWithAnalytics, insertRowWithAnalytics, mergeCellsWithAnalytics, setColorWithAnalytics, setTableAlignmentWithAnalytics, sortColumnWithAnalytics, splitCellWithAnalytics, toggleHeaderColumnWithAnalytics, toggleHeaderRowWithAnalytics, toggleNumberColumnWithAnalytics, toggleTableLockWithAnalytics, wrapTableInExpandWithAnalytics } from './commands-with-analytics';
|
|
24
24
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
25
25
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
26
26
|
import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizing/utils/resize-state';
|
|
@@ -30,6 +30,7 @@ import { TableCssClassName } from './types';
|
|
|
30
30
|
import { FloatingAlignmentButtons } from './ui/FloatingAlignmentButtons/FloatingAlignmentButtons';
|
|
31
31
|
import { DisplayModeIcon } from './ui/icons';
|
|
32
32
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
|
|
33
|
+
import { normaliseAlignment } from './utils/alignment';
|
|
33
34
|
export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
|
|
34
35
|
var formatMessage = _ref.formatMessage;
|
|
35
36
|
var optionItem = getBooleanFF('platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33') ? 'item-checkbox' : 'item';
|
|
@@ -318,7 +319,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
318
319
|
var nodeType = state.schema.nodes.table;
|
|
319
320
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
320
321
|
var alignmentMenu;
|
|
321
|
-
|
|
322
|
+
var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
323
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
322
324
|
var cellItems;
|
|
323
325
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
324
326
|
var columnSettingsItems;
|
|
@@ -582,8 +584,12 @@ var highlightColumnsHandler = function highlightColumnsHandler(state, dispatch)
|
|
|
582
584
|
}
|
|
583
585
|
return false;
|
|
584
586
|
};
|
|
585
|
-
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(
|
|
587
|
+
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6, editorAnalyticsAPI) {
|
|
586
588
|
var formatMessage = _ref6.formatMessage;
|
|
589
|
+
var tableObject = findTable(editorState.selection);
|
|
590
|
+
if (!tableObject) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
587
593
|
var alignmentIcons = [{
|
|
588
594
|
id: 'editor.table.alignLeft',
|
|
589
595
|
value: 'align-start',
|
|
@@ -603,17 +609,17 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(state,
|
|
|
603
609
|
var id = alignmentIcon.id,
|
|
604
610
|
value = alignmentIcon.value,
|
|
605
611
|
icon = alignmentIcon.icon;
|
|
612
|
+
var currentLayout = tableObject.node.attrs.layout;
|
|
606
613
|
return {
|
|
607
614
|
id: id,
|
|
608
615
|
type: 'button',
|
|
609
616
|
icon: icon,
|
|
610
617
|
title: formatMessage(layoutToMessages[value]),
|
|
611
|
-
selected:
|
|
612
|
-
|
|
613
|
-
onClick: makeAlignment()
|
|
618
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
619
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(value, currentLayout, INPUT_METHOD.FLOATING_TB)
|
|
614
620
|
};
|
|
615
621
|
});
|
|
616
|
-
var
|
|
622
|
+
var alignmentItemOptions = {
|
|
617
623
|
render: function render(props) {
|
|
618
624
|
return jsx(FloatingAlignmentButtons, _extends({
|
|
619
625
|
alignmentButtons: alignmentButtons
|
|
@@ -622,24 +628,20 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(state,
|
|
|
622
628
|
width: 60,
|
|
623
629
|
height: 32
|
|
624
630
|
};
|
|
631
|
+
var selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
625
632
|
var alignmentToolbarItem = [{
|
|
626
633
|
id: 'table-layout',
|
|
627
634
|
testId: 'table-layout-dropdown',
|
|
628
635
|
type: 'dropdown',
|
|
629
|
-
options:
|
|
636
|
+
options: alignmentItemOptions,
|
|
630
637
|
title: formatMessage(messages.tableAlignmentOptions),
|
|
631
|
-
|
|
632
|
-
icon: EditorAlignImageCenter // TODO - get the correct icon based on the selected layout attr
|
|
638
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
633
639
|
}];
|
|
634
640
|
return alignmentToolbarItem;
|
|
635
641
|
};
|
|
636
|
-
var
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
// TODO Add alignment logic here
|
|
643
|
-
return true;
|
|
644
|
-
};
|
|
642
|
+
export var getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
643
|
+
var selectedAlignment = selectedNode.attrs.layout;
|
|
644
|
+
return alignmentIcons.find(function (icon) {
|
|
645
|
+
return icon.value === normaliseAlignment(selectedAlignment);
|
|
646
|
+
});
|
|
645
647
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
3
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
4
|
+
*/
|
|
5
|
+
export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
6
|
+
return layout === 'center' || layout === 'align-start' ? layout : 'center';
|
|
7
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
@@ -35,3 +36,4 @@ export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTML
|
|
|
35
36
|
}) => boolean;
|
|
36
37
|
export declare const addBoldInEmptyHeaderCells: (tableCellHeader: ContentNodeWithPos) => Command;
|
|
37
38
|
export declare const updateWidthToWidest: (widthToWidest: WidthToWidest) => Command;
|
|
39
|
+
export declare const setTableAlignment: (newAlignment: TableLayout) => EditorCommand;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next/src/types';
|
|
2
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
3
|
import type { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
3
4
|
import { INPUT_METHOD, TABLE_DISPLAY_MODE } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
@@ -6,7 +7,7 @@ import type { Command, GetEditorContainerWidth } from '@atlaskit/editor-common/t
|
|
|
6
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
7
8
|
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
8
9
|
import type { ResizeStateWithAnalytics } from './pm-plugins/table-resizing/utils';
|
|
9
|
-
import type { InsertRowMethods, InsertRowOptions, RowInsertPosition } from './types';
|
|
10
|
+
import type { AlignmentOptions, InsertRowMethods, InsertRowOptions, RowInsertPosition } from './types';
|
|
10
11
|
export declare const emptyMultipleCellsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition?: number) => Command;
|
|
11
12
|
export declare const mergeCellsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
12
13
|
export declare const splitCellWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
@@ -28,3 +29,4 @@ export declare const sortColumnWithAnalytics: (editorAnalyticsAPI: EditorAnalyti
|
|
|
28
29
|
export declare const distributeColumnsWidthsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU, { resizeState, table, attributes }: ResizeStateWithAnalytics) => Command;
|
|
29
30
|
export declare const wrapTableInExpandWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
30
31
|
export declare const toggleTableLockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (displayMode: TABLE_DISPLAY_MODE | null, inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
32
|
+
export declare const setTableAlignmentWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (newAlignment: AlignmentOptions, previousAlignment: TableLayout, inputMethod: INPUT_METHOD.FLOATING_TB) => Command;
|
package/dist/types/toolbar.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
5
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
7
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
6
8
|
import type { TablePluginOptions } from './plugin';
|
|
7
|
-
import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
9
|
+
import type { AlignmentOptions, PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
8
10
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
9
11
|
export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => FloatingToolbarDropdown<Command>;
|
|
10
12
|
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
@@ -12,4 +14,11 @@ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rec
|
|
|
12
14
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null, options?: TablePluginOptions) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
13
15
|
export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
14
16
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
15
|
-
|
|
17
|
+
type AlignmentIcon = {
|
|
18
|
+
id?: string;
|
|
19
|
+
value: AlignmentOptions;
|
|
20
|
+
icon: React.ComponentClass<any>;
|
|
21
|
+
};
|
|
22
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Array<FloatingToolbarDropdown<Command>>;
|
|
23
|
+
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
24
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEn
|
|
|
39
39
|
isWholeTableInDanger?: boolean;
|
|
40
40
|
};
|
|
41
41
|
export type TableSharedState = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'>;
|
|
42
|
+
export type AlignmentOptions = 'center' | 'align-start';
|
|
42
43
|
export type InsertRowMethods = INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.BUTTON | INPUT_METHOD.SHORTCUT | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU;
|
|
43
44
|
export interface PluginConfig {
|
|
44
45
|
advanced?: boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { AlignmentOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
6
|
+
*/
|
|
7
|
+
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
3
|
import type { Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
@@ -35,3 +36,4 @@ export declare const autoSizeTable: (view: EditorView, node: PMNode, table: HTML
|
|
|
35
36
|
}) => boolean;
|
|
36
37
|
export declare const addBoldInEmptyHeaderCells: (tableCellHeader: ContentNodeWithPos) => Command;
|
|
37
38
|
export declare const updateWidthToWidest: (widthToWidest: WidthToWidest) => Command;
|
|
39
|
+
export declare const setTableAlignment: (newAlignment: TableLayout) => EditorCommand;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next/src/types';
|
|
2
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
3
|
import type { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
3
4
|
import { INPUT_METHOD, TABLE_DISPLAY_MODE } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
@@ -6,7 +7,7 @@ import type { Command, GetEditorContainerWidth } from '@atlaskit/editor-common/t
|
|
|
6
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/dist/types/view';
|
|
7
8
|
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
8
9
|
import type { ResizeStateWithAnalytics } from './pm-plugins/table-resizing/utils';
|
|
9
|
-
import type { InsertRowMethods, InsertRowOptions, RowInsertPosition } from './types';
|
|
10
|
+
import type { AlignmentOptions, InsertRowMethods, InsertRowOptions, RowInsertPosition } from './types';
|
|
10
11
|
export declare const emptyMultipleCellsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition?: number) => Command;
|
|
11
12
|
export declare const mergeCellsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
12
13
|
export declare const splitCellWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
@@ -28,3 +29,4 @@ export declare const sortColumnWithAnalytics: (editorAnalyticsAPI: EditorAnalyti
|
|
|
28
29
|
export declare const distributeColumnsWidthsWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU, { resizeState, table, attributes }: ResizeStateWithAnalytics) => Command;
|
|
29
30
|
export declare const wrapTableInExpandWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
30
31
|
export declare const toggleTableLockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (displayMode: TABLE_DISPLAY_MODE | null, inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) => Command;
|
|
32
|
+
export declare const setTableAlignmentWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => (newAlignment: AlignmentOptions, previousAlignment: TableLayout, inputMethod: INPUT_METHOD.FLOATING_TB) => Command;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
5
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
7
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
6
8
|
import type { TablePluginOptions } from './plugin';
|
|
7
|
-
import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
9
|
+
import type { AlignmentOptions, PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
8
10
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
9
11
|
export declare const getToolbarCellOptionsConfig: (editorState: EditorState, editorView: EditorView | undefined | null, initialSelectionRect: Rect, { formatMessage }: ToolbarMenuContext, getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => FloatingToolbarDropdown<Command>;
|
|
10
12
|
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
@@ -12,4 +14,11 @@ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rec
|
|
|
12
14
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null, options?: TablePluginOptions) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
13
15
|
export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
14
16
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
15
|
-
|
|
17
|
+
type AlignmentIcon = {
|
|
18
|
+
id?: string;
|
|
19
|
+
value: AlignmentOptions;
|
|
20
|
+
icon: React.ComponentClass<any>;
|
|
21
|
+
};
|
|
22
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Array<FloatingToolbarDropdown<Command>>;
|
|
23
|
+
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
24
|
+
export {};
|
|
@@ -39,6 +39,7 @@ export type TableSharedStateInternal = Pick<TablePluginState, 'isFullWidthModeEn
|
|
|
39
39
|
isWholeTableInDanger?: boolean;
|
|
40
40
|
};
|
|
41
41
|
export type TableSharedState = Pick<TablePluginState, 'isFullWidthModeEnabled' | 'wasFullWidthModeEnabled'>;
|
|
42
|
+
export type AlignmentOptions = 'center' | 'align-start';
|
|
42
43
|
export type InsertRowMethods = INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.BUTTON | INPUT_METHOD.SHORTCUT | INPUT_METHOD.KEYBOARD | INPUT_METHOD.FLOATING_TB | INPUT_METHOD.TABLE_CONTEXT_MENU;
|
|
43
44
|
export interface PluginConfig {
|
|
44
45
|
advanced?: boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { AlignmentOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
6
|
+
*/
|
|
7
|
+
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.16.1",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"runReact18": false
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/adf-schema": "^36.
|
|
31
|
+
"@atlaskit/adf-schema": "^36.8.0",
|
|
32
32
|
"@atlaskit/button": "^17.14.0",
|
|
33
33
|
"@atlaskit/custom-steps": "^0.2.0",
|
|
34
|
-
"@atlaskit/editor-common": "^80.
|
|
34
|
+
"@atlaskit/editor-common": "^80.4.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.2.0",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"@atlaskit/editor-shared-styles": "^2.11.0",
|
|
45
45
|
"@atlaskit/editor-tables": "^2.7.0",
|
|
46
46
|
"@atlaskit/icon": "^22.2.0",
|
|
47
|
-
"@atlaskit/menu": "^2.
|
|
47
|
+
"@atlaskit/menu": "^2.3.0",
|
|
48
48
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
49
49
|
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
50
50
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.3.0",
|
|
51
51
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.0",
|
|
52
|
-
"@atlaskit/primitives": "^6.
|
|
52
|
+
"@atlaskit/primitives": "^6.2.0",
|
|
53
53
|
"@atlaskit/theme": "^12.8.0",
|
|
54
54
|
"@atlaskit/toggle": "^13.1.0",
|
|
55
55
|
"@atlaskit/tokens": "^1.48.0",
|
|
@@ -139,9 +139,6 @@
|
|
|
139
139
|
},
|
|
140
140
|
"platform.editor.table.live-pages-sorting_4malx": {
|
|
141
141
|
"type": "boolean"
|
|
142
|
-
},
|
|
143
|
-
"platform.editor.table.allow-table-alignment": {
|
|
144
|
-
"type": "boolean"
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
144
|
}
|
package/src/commands/misc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isEqual from 'lodash/isEqual';
|
|
2
2
|
|
|
3
|
-
import type { CellAttributes } from '@atlaskit/adf-schema';
|
|
4
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { CellAttributes, TableLayout } from '@atlaskit/adf-schema';
|
|
4
|
+
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
5
5
|
import {
|
|
6
6
|
closestElement,
|
|
7
7
|
isParagraph,
|
|
@@ -270,8 +270,8 @@ export const getTableSelectionType = (selection: Selection) => {
|
|
|
270
270
|
return selection.isRowSelection()
|
|
271
271
|
? 'row'
|
|
272
272
|
: selection.isColSelection()
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
? 'column'
|
|
274
|
+
: undefined;
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
|
|
@@ -313,8 +313,8 @@ export const getTableElementMoveTypeBySlice = (
|
|
|
313
313
|
return map.width === slicedMap.width
|
|
314
314
|
? 'row'
|
|
315
315
|
: map.height === slicedMap.height
|
|
316
|
-
|
|
317
|
-
|
|
316
|
+
? 'column'
|
|
317
|
+
: undefined;
|
|
318
318
|
} catch (e) {
|
|
319
319
|
return undefined;
|
|
320
320
|
}
|
|
@@ -809,3 +809,25 @@ export const updateWidthToWidest = (widthToWidest: WidthToWidest) =>
|
|
|
809
809
|
},
|
|
810
810
|
};
|
|
811
811
|
});
|
|
812
|
+
|
|
813
|
+
export const setTableAlignment =
|
|
814
|
+
(newAlignment: TableLayout): EditorCommand =>
|
|
815
|
+
({ tr }) => {
|
|
816
|
+
const tableObject = findTable(tr.selection);
|
|
817
|
+
|
|
818
|
+
if (!tableObject) {
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const nextTableAttrs = {
|
|
823
|
+
...tableObject.node.attrs,
|
|
824
|
+
layout: newAlignment,
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta(
|
|
828
|
+
'scrollIntoView',
|
|
829
|
+
false,
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
return tr;
|
|
833
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next/src/types';
|
|
2
2
|
|
|
3
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
3
4
|
import { tableBackgroundColorPalette } from '@atlaskit/adf-schema';
|
|
4
5
|
import type { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
5
6
|
import {
|
|
@@ -40,6 +41,7 @@ import {
|
|
|
40
41
|
deleteTableIfSelected,
|
|
41
42
|
getTableSelectionType,
|
|
42
43
|
setMultipleCellAttrs,
|
|
44
|
+
setTableAlignment,
|
|
43
45
|
} from './commands/misc';
|
|
44
46
|
import { sortByColumn } from './commands/sort';
|
|
45
47
|
import { splitCell } from './commands/split-cell';
|
|
@@ -55,6 +57,7 @@ import { distributeColumnsWidths } from './pm-plugins/table-resizing/commands';
|
|
|
55
57
|
import type { ResizeStateWithAnalytics } from './pm-plugins/table-resizing/utils';
|
|
56
58
|
import { deleteRows, mergeCells } from './transforms';
|
|
57
59
|
import type {
|
|
60
|
+
AlignmentOptions,
|
|
58
61
|
InsertRowMethods,
|
|
59
62
|
InsertRowOptions,
|
|
60
63
|
RowInsertPosition,
|
|
@@ -691,4 +694,38 @@ export const toggleTableLockWithAnalytics =
|
|
|
691
694
|
eventType: EVENT_TYPE.TRACK,
|
|
692
695
|
};
|
|
693
696
|
})(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
|
|
694
|
-
|
|
697
|
+
|
|
698
|
+
export const setTableAlignmentWithAnalytics =
|
|
699
|
+
(editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
|
|
700
|
+
(
|
|
701
|
+
newAlignment: AlignmentOptions,
|
|
702
|
+
// previous alignment could be a breakout value, if so use 'null' to indicate alignment was not previously set
|
|
703
|
+
previousAlignment: TableLayout,
|
|
704
|
+
inputMethod: INPUT_METHOD.FLOATING_TB,
|
|
705
|
+
) =>
|
|
706
|
+
withEditorAnalyticsAPI((state) => {
|
|
707
|
+
const { table, totalRowCount, totalColumnCount } = getSelectedTableInfo(
|
|
708
|
+
state.selection,
|
|
709
|
+
);
|
|
710
|
+
|
|
711
|
+
return {
|
|
712
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
713
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
714
|
+
actionSubjectId: null,
|
|
715
|
+
eventType: EVENT_TYPE.TRACK,
|
|
716
|
+
attributes: {
|
|
717
|
+
tableWidth: table?.node.attrs.width,
|
|
718
|
+
newAlignment,
|
|
719
|
+
previousAlignment:
|
|
720
|
+
previousAlignment === 'center' ||
|
|
721
|
+
previousAlignment === 'align-start'
|
|
722
|
+
? previousAlignment
|
|
723
|
+
: null,
|
|
724
|
+
totalRowCount,
|
|
725
|
+
totalColumnCount,
|
|
726
|
+
inputMethod,
|
|
727
|
+
},
|
|
728
|
+
};
|
|
729
|
+
})(editorAnalyticsAPI)(
|
|
730
|
+
editorCommandToPMCommand(setTableAlignment(newAlignment)),
|
|
731
|
+
);
|
package/src/plugin.tsx
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
table,
|
|
5
|
-
tableCell,
|
|
6
|
-
tableHeader,
|
|
7
|
-
tableRow,
|
|
8
|
-
tableStage0,
|
|
9
|
-
} from '@atlaskit/adf-schema';
|
|
3
|
+
import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
|
|
10
4
|
import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
|
|
11
5
|
import {
|
|
12
6
|
ACTION,
|
|
@@ -234,14 +228,8 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
234
228
|
},
|
|
235
229
|
|
|
236
230
|
nodes() {
|
|
237
|
-
const tableNode =
|
|
238
|
-
options?.isTableScalingEnabled &&
|
|
239
|
-
getBooleanFF('platform.editor.table.preserve-widths-with-lock-button')
|
|
240
|
-
? tableStage0
|
|
241
|
-
: table;
|
|
242
|
-
|
|
243
231
|
return [
|
|
244
|
-
{ name: 'table', node:
|
|
232
|
+
{ name: 'table', node: table },
|
|
245
233
|
{ name: 'tableHeader', node: tableHeader },
|
|
246
234
|
{ name: 'tableRow', node: tableRow },
|
|
247
235
|
{ name: 'tableCell', node: tableCell },
|
package/src/toolbar.tsx
CHANGED
|
@@ -75,6 +75,7 @@ import {
|
|
|
75
75
|
insertRowWithAnalytics,
|
|
76
76
|
mergeCellsWithAnalytics,
|
|
77
77
|
setColorWithAnalytics,
|
|
78
|
+
setTableAlignmentWithAnalytics,
|
|
78
79
|
sortColumnWithAnalytics,
|
|
79
80
|
splitCellWithAnalytics,
|
|
80
81
|
toggleHeaderColumnWithAnalytics,
|
|
@@ -90,6 +91,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
|
|
|
90
91
|
import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
91
92
|
import { canMergeCells } from './transforms';
|
|
92
93
|
import type {
|
|
94
|
+
AlignmentOptions,
|
|
93
95
|
PluginConfig,
|
|
94
96
|
ToolbarMenuConfig,
|
|
95
97
|
ToolbarMenuContext,
|
|
@@ -104,6 +106,7 @@ import {
|
|
|
104
106
|
getSelectedRowIndexes,
|
|
105
107
|
isTableNested,
|
|
106
108
|
} from './utils';
|
|
109
|
+
import { normaliseAlignment } from './utils/alignment';
|
|
107
110
|
|
|
108
111
|
export const getToolbarMenuConfig = (
|
|
109
112
|
config: ToolbarMenuConfig,
|
|
@@ -479,12 +482,13 @@ export const getToolbarConfig =
|
|
|
479
482
|
);
|
|
480
483
|
|
|
481
484
|
let alignmentMenu: Array<FloatingToolbarItem<Command>>;
|
|
485
|
+
const isNested =
|
|
486
|
+
pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
482
487
|
|
|
483
|
-
alignmentMenu =
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
: [];
|
|
488
|
+
alignmentMenu =
|
|
489
|
+
options?.isTableAlignmentEnabled && !isNested
|
|
490
|
+
? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI)
|
|
491
|
+
: [];
|
|
488
492
|
|
|
489
493
|
let cellItems: Array<FloatingToolbarItem<Command>>;
|
|
490
494
|
cellItems = pluginState.isDragAndDropEnabled
|
|
@@ -886,16 +890,22 @@ const highlightColumnsHandler = (
|
|
|
886
890
|
return false;
|
|
887
891
|
};
|
|
888
892
|
|
|
893
|
+
type AlignmentIcon = {
|
|
894
|
+
id?: string;
|
|
895
|
+
value: AlignmentOptions;
|
|
896
|
+
icon: React.ComponentClass<any>;
|
|
897
|
+
};
|
|
898
|
+
|
|
889
899
|
export const getAlignmentOptionsConfig = (
|
|
890
|
-
|
|
900
|
+
editorState: EditorState,
|
|
891
901
|
{ formatMessage }: ToolbarMenuContext,
|
|
892
902
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
893
903
|
): Array<FloatingToolbarDropdown<Command>> => {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
}
|
|
904
|
+
const tableObject = findTable(editorState.selection);
|
|
905
|
+
|
|
906
|
+
if (!tableObject) {
|
|
907
|
+
return [];
|
|
908
|
+
}
|
|
899
909
|
|
|
900
910
|
const alignmentIcons: AlignmentIcon[] = [
|
|
901
911
|
{
|
|
@@ -911,7 +921,7 @@ export const getAlignmentOptionsConfig = (
|
|
|
911
921
|
];
|
|
912
922
|
|
|
913
923
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
914
|
-
const layoutToMessages: Record<
|
|
924
|
+
const layoutToMessages: Record<AlignmentOptions, any> = {
|
|
915
925
|
center: messages.alignTableCenter,
|
|
916
926
|
'align-start': messages.alignTableLeft,
|
|
917
927
|
};
|
|
@@ -919,18 +929,24 @@ export const getAlignmentOptionsConfig = (
|
|
|
919
929
|
const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>(
|
|
920
930
|
(alignmentIcon) => {
|
|
921
931
|
const { id, value, icon } = alignmentIcon;
|
|
932
|
+
const currentLayout = tableObject.node.attrs.layout;
|
|
933
|
+
|
|
922
934
|
return {
|
|
923
935
|
id: id,
|
|
924
936
|
type: 'button',
|
|
925
937
|
icon: icon,
|
|
926
938
|
title: formatMessage(layoutToMessages[value]),
|
|
927
|
-
selected:
|
|
928
|
-
onClick:
|
|
939
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
940
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
|
|
941
|
+
value,
|
|
942
|
+
currentLayout,
|
|
943
|
+
INPUT_METHOD.FLOATING_TB
|
|
944
|
+
),
|
|
929
945
|
};
|
|
930
946
|
},
|
|
931
947
|
);
|
|
932
948
|
|
|
933
|
-
const
|
|
949
|
+
const alignmentItemOptions: DropdownOptions<Command> = {
|
|
934
950
|
render: (props) => {
|
|
935
951
|
return (
|
|
936
952
|
<FloatingAlignmentButtons
|
|
@@ -943,28 +959,32 @@ export const getAlignmentOptionsConfig = (
|
|
|
943
959
|
height: 32,
|
|
944
960
|
};
|
|
945
961
|
|
|
962
|
+
const selectedAlignmentIcon = getSelectedAlignmentIcon(
|
|
963
|
+
alignmentIcons,
|
|
964
|
+
tableObject.node,
|
|
965
|
+
);
|
|
966
|
+
|
|
946
967
|
const alignmentToolbarItem: Array<FloatingToolbarDropdown<Command>> = [
|
|
947
968
|
{
|
|
948
969
|
id: 'table-layout',
|
|
949
970
|
testId: 'table-layout-dropdown',
|
|
950
971
|
type: 'dropdown',
|
|
951
|
-
options:
|
|
952
|
-
title: formatMessage(messages.tableAlignmentOptions),
|
|
953
|
-
icon:
|
|
972
|
+
options: alignmentItemOptions,
|
|
973
|
+
title: formatMessage(messages.tableAlignmentOptions),
|
|
974
|
+
icon: selectedAlignmentIcon?.icon,
|
|
954
975
|
},
|
|
955
976
|
];
|
|
956
977
|
|
|
957
978
|
return alignmentToolbarItem;
|
|
958
979
|
};
|
|
959
980
|
|
|
960
|
-
const
|
|
961
|
-
|
|
962
|
-
|
|
981
|
+
export const getSelectedAlignmentIcon = (
|
|
982
|
+
alignmentIcons: AlignmentIcon[],
|
|
983
|
+
selectedNode: PMNode,
|
|
984
|
+
) => {
|
|
985
|
+
const selectedAlignment = selectedNode.attrs.layout;
|
|
963
986
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
// TODO Add alignment logic here
|
|
968
|
-
return true;
|
|
969
|
-
};
|
|
987
|
+
return alignmentIcons.find(
|
|
988
|
+
(icon) => icon.value === normaliseAlignment(selectedAlignment),
|
|
989
|
+
);
|
|
970
990
|
};
|
package/src/types.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
|
|
3
|
+
import type { AlignmentOptions } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
7
|
+
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
|
+
*/
|
|
9
|
+
export const normaliseAlignment = (layout: TableLayout): AlignmentOptions =>
|
|
10
|
+
layout === 'center' || layout === 'align-start' ? layout : 'center';
|