@atlaskit/editor-plugin-table 7.16.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 +11 -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 +9 -26
- 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 +8 -25
- 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 +8 -27
- 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 +3 -4
- 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 +3 -4
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/utils/alignment.d.ts +7 -0
- package/package.json +2 -2
- 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 +16 -37
- package/src/types.ts +2 -0
- package/src/utils/alignment.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
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
|
+
|
|
3
14
|
## 7.16.0
|
|
4
15
|
|
|
5
16
|
### 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
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.getToolbarMenuConfig = exports.getToolbarConfig = exports.getToolbarCellOptionsConfig = exports.getSelectedAlignmentIcon = exports.getLockBtnConfig = exports.getDistributeConfig = exports.getClosestSelectionRect = exports.getClosestSelectionOrTableRect = exports.getAlignmentOptionsConfig = void 0;
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
11
|
var _react = require("@emotion/react");
|
|
@@ -38,10 +37,11 @@ var _types = require("./types");
|
|
|
38
37
|
var _FloatingAlignmentButtons = require("./ui/FloatingAlignmentButtons/FloatingAlignmentButtons");
|
|
39
38
|
var _icons = require("./ui/icons");
|
|
40
39
|
var _utils4 = require("./utils");
|
|
40
|
+
var _alignment = require("./utils/alignment");
|
|
41
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); }
|
|
42
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; }
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/** @jsx jsx */
|
|
44
|
+
|
|
45
45
|
var getToolbarMenuConfig = exports.getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
|
|
46
46
|
var formatMessage = _ref.formatMessage;
|
|
47
47
|
var optionItem = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33') ? 'item-checkbox' : 'item';
|
|
@@ -331,7 +331,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(getE
|
|
|
331
331
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
332
332
|
var alignmentMenu;
|
|
333
333
|
var isNested = pluginState.tablePos && (0, _utils4.isTableNested)(state, pluginState.tablePos);
|
|
334
|
-
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
|
|
334
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
335
335
|
var cellItems;
|
|
336
336
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
337
337
|
var columnSettingsItems;
|
|
@@ -595,7 +595,7 @@ var highlightColumnsHandler = function highlightColumnsHandler(state, dispatch)
|
|
|
595
595
|
}
|
|
596
596
|
return false;
|
|
597
597
|
};
|
|
598
|
-
var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6) {
|
|
598
|
+
var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6, editorAnalyticsAPI) {
|
|
599
599
|
var formatMessage = _ref6.formatMessage;
|
|
600
600
|
var tableObject = (0, _utils3.findTable)(editorState.selection);
|
|
601
601
|
if (!tableObject) {
|
|
@@ -620,13 +620,14 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
620
620
|
var id = alignmentIcon.id,
|
|
621
621
|
value = alignmentIcon.value,
|
|
622
622
|
icon = alignmentIcon.icon;
|
|
623
|
+
var currentLayout = tableObject.node.attrs.layout;
|
|
623
624
|
return {
|
|
624
625
|
id: id,
|
|
625
626
|
type: 'button',
|
|
626
627
|
icon: icon,
|
|
627
628
|
title: formatMessage(layoutToMessages[value]),
|
|
628
|
-
selected:
|
|
629
|
-
onClick:
|
|
629
|
+
selected: (0, _alignment.normaliseAlignment)(currentLayout) === value,
|
|
630
|
+
onClick: (0, _commandsWithAnalytics.setTableAlignmentWithAnalytics)(editorAnalyticsAPI)(value, currentLayout, _analytics.INPUT_METHOD.FLOATING_TB)
|
|
630
631
|
};
|
|
631
632
|
});
|
|
632
633
|
var alignmentItemOptions = {
|
|
@@ -649,27 +650,9 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
649
650
|
}];
|
|
650
651
|
return alignmentToolbarItem;
|
|
651
652
|
};
|
|
652
|
-
var alignTable = function alignTable(nextLayoutValue) {
|
|
653
|
-
return function (state, dispatch) {
|
|
654
|
-
var tableObject = (0, _utils3.findTable)(state.selection);
|
|
655
|
-
if (!tableObject || !dispatch) {
|
|
656
|
-
return false;
|
|
657
|
-
}
|
|
658
|
-
var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
|
|
659
|
-
layout: nextLayoutValue
|
|
660
|
-
});
|
|
661
|
-
var tr = state.tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs);
|
|
662
|
-
tr.setMeta('scrollIntoView', false);
|
|
663
|
-
|
|
664
|
-
// TODO - insert analytics here for layout selection
|
|
665
|
-
|
|
666
|
-
dispatch(tr);
|
|
667
|
-
return true;
|
|
668
|
-
};
|
|
669
|
-
};
|
|
670
653
|
var getSelectedAlignmentIcon = exports.getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
671
654
|
var selectedAlignment = selectedNode.attrs.layout;
|
|
672
655
|
return alignmentIcons.find(function (icon) {
|
|
673
|
-
return icon.value === (
|
|
656
|
+
return icon.value === (0, _alignment.normaliseAlignment)(selectedAlignment);
|
|
674
657
|
});
|
|
675
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) => {
|
|
@@ -316,7 +317,7 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
316
317
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
317
318
|
let alignmentMenu;
|
|
318
319
|
const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
319
|
-
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
|
|
320
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
320
321
|
let cellItems;
|
|
321
322
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
322
323
|
let columnSettingsItems;
|
|
@@ -563,7 +564,7 @@ const highlightColumnsHandler = (state, dispatch) => {
|
|
|
563
564
|
};
|
|
564
565
|
export const getAlignmentOptionsConfig = (editorState, {
|
|
565
566
|
formatMessage
|
|
566
|
-
}) => {
|
|
567
|
+
}, editorAnalyticsAPI) => {
|
|
567
568
|
const tableObject = findTable(editorState.selection);
|
|
568
569
|
if (!tableObject) {
|
|
569
570
|
return [];
|
|
@@ -589,13 +590,14 @@ export const getAlignmentOptionsConfig = (editorState, {
|
|
|
589
590
|
value,
|
|
590
591
|
icon
|
|
591
592
|
} = alignmentIcon;
|
|
593
|
+
const currentLayout = tableObject.node.attrs.layout;
|
|
592
594
|
return {
|
|
593
595
|
id: id,
|
|
594
596
|
type: 'button',
|
|
595
597
|
icon: icon,
|
|
596
598
|
title: formatMessage(layoutToMessages[value]),
|
|
597
|
-
selected:
|
|
598
|
-
onClick:
|
|
599
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
600
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(value, currentLayout, INPUT_METHOD.FLOATING_TB)
|
|
599
601
|
};
|
|
600
602
|
});
|
|
601
603
|
const alignmentItemOptions = {
|
|
@@ -618,26 +620,7 @@ export const getAlignmentOptionsConfig = (editorState, {
|
|
|
618
620
|
}];
|
|
619
621
|
return alignmentToolbarItem;
|
|
620
622
|
};
|
|
621
|
-
const alignTable = nextLayoutValue => {
|
|
622
|
-
return (state, dispatch) => {
|
|
623
|
-
const tableObject = findTable(state.selection);
|
|
624
|
-
if (!tableObject || !dispatch) {
|
|
625
|
-
return false;
|
|
626
|
-
}
|
|
627
|
-
const nextTableAttrs = {
|
|
628
|
-
...tableObject.node.attrs,
|
|
629
|
-
layout: nextLayoutValue
|
|
630
|
-
};
|
|
631
|
-
const tr = state.tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs);
|
|
632
|
-
tr.setMeta('scrollIntoView', false);
|
|
633
|
-
|
|
634
|
-
// TODO - insert analytics here for layout selection
|
|
635
|
-
|
|
636
|
-
dispatch(tr);
|
|
637
|
-
return true;
|
|
638
|
-
};
|
|
639
|
-
};
|
|
640
623
|
export const getSelectedAlignmentIcon = (alignmentIcons, selectedNode) => {
|
|
641
624
|
const selectedAlignment = selectedNode.attrs.layout;
|
|
642
|
-
return alignmentIcons.find(icon => icon.value === (
|
|
625
|
+
return alignmentIcons.find(icon => icon.value === normaliseAlignment(selectedAlignment));
|
|
643
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
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
3
|
/** @jsx jsx */
|
|
7
4
|
import { jsx } from '@emotion/react';
|
|
8
5
|
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
@@ -23,7 +20,7 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
|
23
20
|
import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
|
|
24
21
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
25
22
|
import { clearHoverSelection, hoverColumns, hoverMergedCells, hoverRows, hoverTable, removeDescendantNodes } from './commands';
|
|
26
|
-
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';
|
|
27
24
|
import { getPluginState } from './pm-plugins/plugin-factory';
|
|
28
25
|
import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing';
|
|
29
26
|
import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizing/utils/resize-state';
|
|
@@ -33,6 +30,7 @@ import { TableCssClassName } from './types';
|
|
|
33
30
|
import { FloatingAlignmentButtons } from './ui/FloatingAlignmentButtons/FloatingAlignmentButtons';
|
|
34
31
|
import { DisplayModeIcon } from './ui/icons';
|
|
35
32
|
import { getMergedCellsPositions, getSelectedColumnIndexes, getSelectedRowIndexes, isTableNested } from './utils';
|
|
33
|
+
import { normaliseAlignment } from './utils/alignment';
|
|
36
34
|
export var getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
|
|
37
35
|
var formatMessage = _ref.formatMessage;
|
|
38
36
|
var optionItem = getBooleanFF('platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33') ? 'item-checkbox' : 'item';
|
|
@@ -322,7 +320,7 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
322
320
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
323
321
|
var alignmentMenu;
|
|
324
322
|
var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
325
|
-
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
|
|
323
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI) : [];
|
|
326
324
|
var cellItems;
|
|
327
325
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
328
326
|
var columnSettingsItems;
|
|
@@ -586,7 +584,7 @@ var highlightColumnsHandler = function highlightColumnsHandler(state, dispatch)
|
|
|
586
584
|
}
|
|
587
585
|
return false;
|
|
588
586
|
};
|
|
589
|
-
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6) {
|
|
587
|
+
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6, editorAnalyticsAPI) {
|
|
590
588
|
var formatMessage = _ref6.formatMessage;
|
|
591
589
|
var tableObject = findTable(editorState.selection);
|
|
592
590
|
if (!tableObject) {
|
|
@@ -611,13 +609,14 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editor
|
|
|
611
609
|
var id = alignmentIcon.id,
|
|
612
610
|
value = alignmentIcon.value,
|
|
613
611
|
icon = alignmentIcon.icon;
|
|
612
|
+
var currentLayout = tableObject.node.attrs.layout;
|
|
614
613
|
return {
|
|
615
614
|
id: id,
|
|
616
615
|
type: 'button',
|
|
617
616
|
icon: icon,
|
|
618
617
|
title: formatMessage(layoutToMessages[value]),
|
|
619
|
-
selected:
|
|
620
|
-
onClick:
|
|
618
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
619
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(value, currentLayout, INPUT_METHOD.FLOATING_TB)
|
|
621
620
|
};
|
|
622
621
|
});
|
|
623
622
|
var alignmentItemOptions = {
|
|
@@ -640,27 +639,9 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editor
|
|
|
640
639
|
}];
|
|
641
640
|
return alignmentToolbarItem;
|
|
642
641
|
};
|
|
643
|
-
var alignTable = function alignTable(nextLayoutValue) {
|
|
644
|
-
return function (state, dispatch) {
|
|
645
|
-
var tableObject = findTable(state.selection);
|
|
646
|
-
if (!tableObject || !dispatch) {
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
|
-
var nextTableAttrs = _objectSpread(_objectSpread({}, tableObject.node.attrs), {}, {
|
|
650
|
-
layout: nextLayoutValue
|
|
651
|
-
});
|
|
652
|
-
var tr = state.tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs);
|
|
653
|
-
tr.setMeta('scrollIntoView', false);
|
|
654
|
-
|
|
655
|
-
// TODO - insert analytics here for layout selection
|
|
656
|
-
|
|
657
|
-
dispatch(tr);
|
|
658
|
-
return true;
|
|
659
|
-
};
|
|
660
|
-
};
|
|
661
642
|
export var getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
662
643
|
var selectedAlignment = selectedNode.attrs.layout;
|
|
663
644
|
return alignmentIcons.find(function (icon) {
|
|
664
|
-
return icon.value === (
|
|
645
|
+
return icon.value === normaliseAlignment(selectedAlignment);
|
|
665
646
|
});
|
|
666
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,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
3
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
3
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
4
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -7,7 +6,7 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
|
7
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
7
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
9
8
|
import type { TablePluginOptions } from './plugin';
|
|
10
|
-
import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
9
|
+
import type { AlignmentOptions, PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
11
10
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
12
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>;
|
|
13
12
|
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
@@ -17,9 +16,9 @@ export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI |
|
|
|
17
16
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
18
17
|
type AlignmentIcon = {
|
|
19
18
|
id?: string;
|
|
20
|
-
value:
|
|
19
|
+
value: AlignmentOptions;
|
|
21
20
|
icon: React.ComponentClass<any>;
|
|
22
21
|
};
|
|
23
|
-
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext) => Array<FloatingToolbarDropdown<Command>>;
|
|
22
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Array<FloatingToolbarDropdown<Command>>;
|
|
24
23
|
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
25
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,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
3
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
3
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
4
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -7,7 +6,7 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
|
7
6
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
8
7
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
9
8
|
import type { TablePluginOptions } from './plugin';
|
|
10
|
-
import type { PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
9
|
+
import type { AlignmentOptions, PluginConfig, ToolbarMenuConfig, ToolbarMenuContext, ToolbarMenuState } from './types';
|
|
11
10
|
export declare const getToolbarMenuConfig: (config: ToolbarMenuConfig, state: ToolbarMenuState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => FloatingToolbarItem<Command>;
|
|
12
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>;
|
|
13
12
|
export declare const getClosestSelectionRect: (state: EditorState) => Rect | undefined;
|
|
@@ -17,9 +16,9 @@ export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI |
|
|
|
17
16
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
18
17
|
type AlignmentIcon = {
|
|
19
18
|
id?: string;
|
|
20
|
-
value:
|
|
19
|
+
value: AlignmentOptions;
|
|
21
20
|
icon: React.ComponentClass<any>;
|
|
22
21
|
};
|
|
23
|
-
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext) => Array<FloatingToolbarDropdown<Command>>;
|
|
22
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Array<FloatingToolbarDropdown<Command>>;
|
|
24
23
|
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
25
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.16.
|
|
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,7 +28,7 @@
|
|
|
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
34
|
"@atlaskit/editor-common": "^80.4.0",
|
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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
3
|
|
|
4
|
-
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
5
4
|
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
6
5
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
7
6
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
@@ -76,6 +75,7 @@ import {
|
|
|
76
75
|
insertRowWithAnalytics,
|
|
77
76
|
mergeCellsWithAnalytics,
|
|
78
77
|
setColorWithAnalytics,
|
|
78
|
+
setTableAlignmentWithAnalytics,
|
|
79
79
|
sortColumnWithAnalytics,
|
|
80
80
|
splitCellWithAnalytics,
|
|
81
81
|
toggleHeaderColumnWithAnalytics,
|
|
@@ -91,6 +91,7 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
|
|
|
91
91
|
import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
|
|
92
92
|
import { canMergeCells } from './transforms';
|
|
93
93
|
import type {
|
|
94
|
+
AlignmentOptions,
|
|
94
95
|
PluginConfig,
|
|
95
96
|
ToolbarMenuConfig,
|
|
96
97
|
ToolbarMenuContext,
|
|
@@ -105,6 +106,7 @@ import {
|
|
|
105
106
|
getSelectedRowIndexes,
|
|
106
107
|
isTableNested,
|
|
107
108
|
} from './utils';
|
|
109
|
+
import { normaliseAlignment } from './utils/alignment';
|
|
108
110
|
|
|
109
111
|
export const getToolbarMenuConfig = (
|
|
110
112
|
config: ToolbarMenuConfig,
|
|
@@ -485,7 +487,7 @@ export const getToolbarConfig =
|
|
|
485
487
|
|
|
486
488
|
alignmentMenu =
|
|
487
489
|
options?.isTableAlignmentEnabled && !isNested
|
|
488
|
-
? getAlignmentOptionsConfig(state, intl)
|
|
490
|
+
? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI)
|
|
489
491
|
: [];
|
|
490
492
|
|
|
491
493
|
let cellItems: Array<FloatingToolbarItem<Command>>;
|
|
@@ -890,13 +892,14 @@ const highlightColumnsHandler = (
|
|
|
890
892
|
|
|
891
893
|
type AlignmentIcon = {
|
|
892
894
|
id?: string;
|
|
893
|
-
value:
|
|
895
|
+
value: AlignmentOptions;
|
|
894
896
|
icon: React.ComponentClass<any>;
|
|
895
897
|
};
|
|
896
898
|
|
|
897
899
|
export const getAlignmentOptionsConfig = (
|
|
898
900
|
editorState: EditorState,
|
|
899
901
|
{ formatMessage }: ToolbarMenuContext,
|
|
902
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
900
903
|
): Array<FloatingToolbarDropdown<Command>> => {
|
|
901
904
|
const tableObject = findTable(editorState.selection);
|
|
902
905
|
|
|
@@ -918,7 +921,7 @@ export const getAlignmentOptionsConfig = (
|
|
|
918
921
|
];
|
|
919
922
|
|
|
920
923
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
921
|
-
const layoutToMessages: Record<
|
|
924
|
+
const layoutToMessages: Record<AlignmentOptions, any> = {
|
|
922
925
|
center: messages.alignTableCenter,
|
|
923
926
|
'align-start': messages.alignTableLeft,
|
|
924
927
|
};
|
|
@@ -926,13 +929,19 @@ export const getAlignmentOptionsConfig = (
|
|
|
926
929
|
const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>(
|
|
927
930
|
(alignmentIcon) => {
|
|
928
931
|
const { id, value, icon } = alignmentIcon;
|
|
932
|
+
const currentLayout = tableObject.node.attrs.layout;
|
|
933
|
+
|
|
929
934
|
return {
|
|
930
935
|
id: id,
|
|
931
936
|
type: 'button',
|
|
932
937
|
icon: icon,
|
|
933
938
|
title: formatMessage(layoutToMessages[value]),
|
|
934
|
-
selected:
|
|
935
|
-
onClick:
|
|
939
|
+
selected: normaliseAlignment(currentLayout) === value,
|
|
940
|
+
onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
|
|
941
|
+
value,
|
|
942
|
+
currentLayout,
|
|
943
|
+
INPUT_METHOD.FLOATING_TB
|
|
944
|
+
),
|
|
936
945
|
};
|
|
937
946
|
},
|
|
938
947
|
);
|
|
@@ -969,34 +978,6 @@ export const getAlignmentOptionsConfig = (
|
|
|
969
978
|
return alignmentToolbarItem;
|
|
970
979
|
};
|
|
971
980
|
|
|
972
|
-
const alignTable = (nextLayoutValue: TableLayout): Command => {
|
|
973
|
-
return (state, dispatch) => {
|
|
974
|
-
const tableObject = findTable(state.selection);
|
|
975
|
-
|
|
976
|
-
if (!tableObject || !dispatch) {
|
|
977
|
-
return false;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
const nextTableAttrs = {
|
|
981
|
-
...tableObject.node.attrs,
|
|
982
|
-
layout: nextLayoutValue,
|
|
983
|
-
};
|
|
984
|
-
|
|
985
|
-
const tr = state.tr.setNodeMarkup(
|
|
986
|
-
tableObject.pos,
|
|
987
|
-
undefined,
|
|
988
|
-
nextTableAttrs,
|
|
989
|
-
);
|
|
990
|
-
|
|
991
|
-
tr.setMeta('scrollIntoView', false);
|
|
992
|
-
|
|
993
|
-
// TODO - insert analytics here for layout selection
|
|
994
|
-
|
|
995
|
-
dispatch(tr);
|
|
996
|
-
return true;
|
|
997
|
-
};
|
|
998
|
-
};
|
|
999
|
-
|
|
1000
981
|
export const getSelectedAlignmentIcon = (
|
|
1001
982
|
alignmentIcons: AlignmentIcon[],
|
|
1002
983
|
selectedNode: PMNode,
|
|
@@ -1004,8 +985,6 @@ export const getSelectedAlignmentIcon = (
|
|
|
1004
985
|
const selectedAlignment = selectedNode.attrs.layout;
|
|
1005
986
|
|
|
1006
987
|
return alignmentIcons.find(
|
|
1007
|
-
(icon) =>
|
|
1008
|
-
icon.value ===
|
|
1009
|
-
(selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment),
|
|
988
|
+
(icon) => icon.value === normaliseAlignment(selectedAlignment),
|
|
1010
989
|
);
|
|
1011
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';
|