@atlaskit/editor-plugin-table 7.15.0 → 7.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/toolbar.js +33 -14
- package/dist/es2019/toolbar.js +29 -12
- package/dist/esm/toolbar.js +32 -11
- package/dist/types/toolbar.d.ts +11 -1
- package/dist/types-ts4.5/toolbar.d.ts +11 -1
- package/package.json +4 -7
- package/src/toolbar.tsx +61 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#100692](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100692)
|
|
8
|
+
[`76587b8092dc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/76587b8092dc) -
|
|
9
|
+
[ux] ED-22924 Table - Created and hooked command to alignment toolbar buttons
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 7.15.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -5,7 +5,8 @@ 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
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
12
|
var _react = require("@emotion/react");
|
|
@@ -39,8 +40,8 @@ var _icons = require("./ui/icons");
|
|
|
39
40
|
var _utils4 = require("./utils");
|
|
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
|
-
|
|
43
|
+
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; }
|
|
44
|
+
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) { (0, _defineProperty2.default)(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; } /** @jsx jsx */
|
|
44
45
|
var getToolbarMenuConfig = exports.getToolbarMenuConfig = function getToolbarMenuConfig(config, state, _ref, editorAnalyticsAPI) {
|
|
45
46
|
var formatMessage = _ref.formatMessage;
|
|
46
47
|
var optionItem = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33') ? 'item-checkbox' : 'item';
|
|
@@ -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) : [];
|
|
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) {
|
|
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',
|
|
@@ -619,12 +625,11 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
619
625
|
type: 'button',
|
|
620
626
|
icon: icon,
|
|
621
627
|
title: formatMessage(layoutToMessages[value]),
|
|
622
|
-
selected:
|
|
623
|
-
|
|
624
|
-
onClick: makeAlignment()
|
|
628
|
+
selected: tableObject.node.attrs.layout === value,
|
|
629
|
+
onClick: alignTable(value)
|
|
625
630
|
};
|
|
626
631
|
});
|
|
627
|
-
var
|
|
632
|
+
var alignmentItemOptions = {
|
|
628
633
|
render: function render(props) {
|
|
629
634
|
return (0, _react.jsx)(_FloatingAlignmentButtons.FloatingAlignmentButtons, (0, _extends2.default)({
|
|
630
635
|
alignmentButtons: alignmentButtons
|
|
@@ -633,24 +638,38 @@ var getAlignmentOptionsConfig = exports.getAlignmentOptionsConfig = function get
|
|
|
633
638
|
width: 60,
|
|
634
639
|
height: 32
|
|
635
640
|
};
|
|
641
|
+
var selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
636
642
|
var alignmentToolbarItem = [{
|
|
637
643
|
id: 'table-layout',
|
|
638
644
|
testId: 'table-layout-dropdown',
|
|
639
645
|
type: 'dropdown',
|
|
640
|
-
options:
|
|
646
|
+
options: alignmentItemOptions,
|
|
641
647
|
title: formatMessage(_messages.tableMessages.tableAlignmentOptions),
|
|
642
|
-
|
|
643
|
-
icon: _alignImageCenter.default // TODO - get the correct icon based on the selected layout attr
|
|
648
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
644
649
|
}];
|
|
645
650
|
return alignmentToolbarItem;
|
|
646
651
|
};
|
|
647
|
-
var
|
|
652
|
+
var alignTable = function alignTable(nextLayoutValue) {
|
|
648
653
|
return function (state, dispatch) {
|
|
649
654
|
var tableObject = (0, _utils3.findTable)(state.selection);
|
|
650
655
|
if (!tableObject || !dispatch) {
|
|
651
656
|
return false;
|
|
652
657
|
}
|
|
653
|
-
|
|
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);
|
|
654
667
|
return true;
|
|
655
668
|
};
|
|
669
|
+
};
|
|
670
|
+
var getSelectedAlignmentIcon = exports.getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
671
|
+
var selectedAlignment = selectedNode.attrs.layout;
|
|
672
|
+
return alignmentIcons.find(function (icon) {
|
|
673
|
+
return icon.value === (selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment);
|
|
674
|
+
});
|
|
656
675
|
};
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -315,7 +315,8 @@ export const getToolbarConfig = (getEditorContainerWidth, editorAnalyticsAPI, ge
|
|
|
315
315
|
const nodeType = state.schema.nodes.table;
|
|
316
316
|
const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
317
317
|
let alignmentMenu;
|
|
318
|
-
|
|
318
|
+
const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
319
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
|
|
319
320
|
let cellItems;
|
|
320
321
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
321
322
|
let columnSettingsItems;
|
|
@@ -560,9 +561,13 @@ const highlightColumnsHandler = (state, dispatch) => {
|
|
|
560
561
|
}
|
|
561
562
|
return false;
|
|
562
563
|
};
|
|
563
|
-
export const getAlignmentOptionsConfig = (
|
|
564
|
+
export const getAlignmentOptionsConfig = (editorState, {
|
|
564
565
|
formatMessage
|
|
565
|
-
}
|
|
566
|
+
}) => {
|
|
567
|
+
const tableObject = findTable(editorState.selection);
|
|
568
|
+
if (!tableObject) {
|
|
569
|
+
return [];
|
|
570
|
+
}
|
|
566
571
|
const alignmentIcons = [{
|
|
567
572
|
id: 'editor.table.alignLeft',
|
|
568
573
|
value: 'align-start',
|
|
@@ -589,12 +594,11 @@ export const getAlignmentOptionsConfig = (state, {
|
|
|
589
594
|
type: 'button',
|
|
590
595
|
icon: icon,
|
|
591
596
|
title: formatMessage(layoutToMessages[value]),
|
|
592
|
-
selected:
|
|
593
|
-
|
|
594
|
-
onClick: makeAlignment()
|
|
597
|
+
selected: tableObject.node.attrs.layout === value,
|
|
598
|
+
onClick: alignTable(value)
|
|
595
599
|
};
|
|
596
600
|
});
|
|
597
|
-
const
|
|
601
|
+
const alignmentItemOptions = {
|
|
598
602
|
render: props => {
|
|
599
603
|
return jsx(FloatingAlignmentButtons, _extends({
|
|
600
604
|
alignmentButtons: alignmentButtons
|
|
@@ -603,24 +607,37 @@ export const getAlignmentOptionsConfig = (state, {
|
|
|
603
607
|
width: 60,
|
|
604
608
|
height: 32
|
|
605
609
|
};
|
|
610
|
+
const selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
606
611
|
const alignmentToolbarItem = [{
|
|
607
612
|
id: 'table-layout',
|
|
608
613
|
testId: 'table-layout-dropdown',
|
|
609
614
|
type: 'dropdown',
|
|
610
|
-
options:
|
|
615
|
+
options: alignmentItemOptions,
|
|
611
616
|
title: formatMessage(messages.tableAlignmentOptions),
|
|
612
|
-
|
|
613
|
-
icon: EditorAlignImageCenter // TODO - get the correct icon based on the selected layout attr
|
|
617
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
614
618
|
}];
|
|
615
619
|
return alignmentToolbarItem;
|
|
616
620
|
};
|
|
617
|
-
const
|
|
621
|
+
const alignTable = nextLayoutValue => {
|
|
618
622
|
return (state, dispatch) => {
|
|
619
623
|
const tableObject = findTable(state.selection);
|
|
620
624
|
if (!tableObject || !dispatch) {
|
|
621
625
|
return false;
|
|
622
626
|
}
|
|
623
|
-
|
|
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);
|
|
624
637
|
return true;
|
|
625
638
|
};
|
|
639
|
+
};
|
|
640
|
+
export const getSelectedAlignmentIcon = (alignmentIcons, selectedNode) => {
|
|
641
|
+
const selectedAlignment = selectedNode.attrs.layout;
|
|
642
|
+
return alignmentIcons.find(icon => icon.value === (selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment));
|
|
626
643
|
};
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
3
|
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; }
|
|
3
6
|
/** @jsx jsx */
|
|
4
7
|
import { jsx } from '@emotion/react';
|
|
5
8
|
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
@@ -318,7 +321,8 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
318
321
|
var nodeType = state.schema.nodes.table;
|
|
319
322
|
var menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
|
|
320
323
|
var alignmentMenu;
|
|
321
|
-
|
|
324
|
+
var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
325
|
+
alignmentMenu = options !== null && options !== void 0 && options.isTableAlignmentEnabled && !isNested ? getAlignmentOptionsConfig(state, intl) : [];
|
|
322
326
|
var cellItems;
|
|
323
327
|
cellItems = pluginState.isDragAndDropEnabled ? [] : getCellItems(state, getEditorView(), intl, getEditorContainerWidth, editorAnalyticsAPI, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled);
|
|
324
328
|
var columnSettingsItems;
|
|
@@ -582,8 +586,12 @@ var highlightColumnsHandler = function highlightColumnsHandler(state, dispatch)
|
|
|
582
586
|
}
|
|
583
587
|
return false;
|
|
584
588
|
};
|
|
585
|
-
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(
|
|
589
|
+
export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(editorState, _ref6) {
|
|
586
590
|
var formatMessage = _ref6.formatMessage;
|
|
591
|
+
var tableObject = findTable(editorState.selection);
|
|
592
|
+
if (!tableObject) {
|
|
593
|
+
return [];
|
|
594
|
+
}
|
|
587
595
|
var alignmentIcons = [{
|
|
588
596
|
id: 'editor.table.alignLeft',
|
|
589
597
|
value: 'align-start',
|
|
@@ -608,12 +616,11 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(state,
|
|
|
608
616
|
type: 'button',
|
|
609
617
|
icon: icon,
|
|
610
618
|
title: formatMessage(layoutToMessages[value]),
|
|
611
|
-
selected:
|
|
612
|
-
|
|
613
|
-
onClick: makeAlignment()
|
|
619
|
+
selected: tableObject.node.attrs.layout === value,
|
|
620
|
+
onClick: alignTable(value)
|
|
614
621
|
};
|
|
615
622
|
});
|
|
616
|
-
var
|
|
623
|
+
var alignmentItemOptions = {
|
|
617
624
|
render: function render(props) {
|
|
618
625
|
return jsx(FloatingAlignmentButtons, _extends({
|
|
619
626
|
alignmentButtons: alignmentButtons
|
|
@@ -622,24 +629,38 @@ export var getAlignmentOptionsConfig = function getAlignmentOptionsConfig(state,
|
|
|
622
629
|
width: 60,
|
|
623
630
|
height: 32
|
|
624
631
|
};
|
|
632
|
+
var selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
|
|
625
633
|
var alignmentToolbarItem = [{
|
|
626
634
|
id: 'table-layout',
|
|
627
635
|
testId: 'table-layout-dropdown',
|
|
628
636
|
type: 'dropdown',
|
|
629
|
-
options:
|
|
637
|
+
options: alignmentItemOptions,
|
|
630
638
|
title: formatMessage(messages.tableAlignmentOptions),
|
|
631
|
-
|
|
632
|
-
icon: EditorAlignImageCenter // TODO - get the correct icon based on the selected layout attr
|
|
639
|
+
icon: selectedAlignmentIcon === null || selectedAlignmentIcon === void 0 ? void 0 : selectedAlignmentIcon.icon
|
|
633
640
|
}];
|
|
634
641
|
return alignmentToolbarItem;
|
|
635
642
|
};
|
|
636
|
-
var
|
|
643
|
+
var alignTable = function alignTable(nextLayoutValue) {
|
|
637
644
|
return function (state, dispatch) {
|
|
638
645
|
var tableObject = findTable(state.selection);
|
|
639
646
|
if (!tableObject || !dispatch) {
|
|
640
647
|
return false;
|
|
641
648
|
}
|
|
642
|
-
|
|
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);
|
|
643
658
|
return true;
|
|
644
659
|
};
|
|
660
|
+
};
|
|
661
|
+
export var getSelectedAlignmentIcon = function getSelectedAlignmentIcon(alignmentIcons, selectedNode) {
|
|
662
|
+
var selectedAlignment = selectedNode.attrs.layout;
|
|
663
|
+
return alignmentIcons.find(function (icon) {
|
|
664
|
+
return icon.value === (selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment);
|
|
665
|
+
});
|
|
645
666
|
};
|
package/dist/types/toolbar.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
1
3
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
4
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
8
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
@@ -12,4 +15,11 @@ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rec
|
|
|
12
15
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null, options?: TablePluginOptions) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
13
16
|
export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
14
17
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
15
|
-
|
|
18
|
+
type AlignmentIcon = {
|
|
19
|
+
id?: string;
|
|
20
|
+
value: TableLayout;
|
|
21
|
+
icon: React.ComponentClass<any>;
|
|
22
|
+
};
|
|
23
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext) => Array<FloatingToolbarDropdown<Command>>;
|
|
24
|
+
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
25
|
+
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
1
3
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
4
|
import type { Command, FloatingToolbarDropdown, FloatingToolbarHandler, FloatingToolbarItem, GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
7
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
5
8
|
import { Rect } from '@atlaskit/editor-tables/table-map';
|
|
@@ -12,4 +15,11 @@ export declare const getClosestSelectionOrTableRect: (state: EditorState) => Rec
|
|
|
12
15
|
export declare const getToolbarConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, getEditorFeatureFlags: GetEditorFeatureFlags, getEditorView: () => EditorView | null, options?: TablePluginOptions) => (config: PluginConfig) => FloatingToolbarHandler;
|
|
13
16
|
export declare const getLockBtnConfig: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) => Command;
|
|
14
17
|
export declare const getDistributeConfig: (getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isTableScalingEnabled?: boolean) => Command;
|
|
15
|
-
|
|
18
|
+
type AlignmentIcon = {
|
|
19
|
+
id?: string;
|
|
20
|
+
value: TableLayout;
|
|
21
|
+
icon: React.ComponentClass<any>;
|
|
22
|
+
};
|
|
23
|
+
export declare const getAlignmentOptionsConfig: (editorState: EditorState, { formatMessage }: ToolbarMenuContext) => Array<FloatingToolbarDropdown<Command>>;
|
|
24
|
+
export declare const getSelectedAlignmentIcon: (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => AlignmentIcon | undefined;
|
|
25
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.16.0",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@atlaskit/adf-schema": "^36.3.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/toolbar.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
3
|
|
|
4
|
+
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
4
5
|
import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
|
|
5
6
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
6
7
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
@@ -479,12 +480,13 @@ export const getToolbarConfig =
|
|
|
479
480
|
);
|
|
480
481
|
|
|
481
482
|
let alignmentMenu: Array<FloatingToolbarItem<Command>>;
|
|
483
|
+
const isNested =
|
|
484
|
+
pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
482
485
|
|
|
483
|
-
alignmentMenu =
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
: [];
|
|
486
|
+
alignmentMenu =
|
|
487
|
+
options?.isTableAlignmentEnabled && !isNested
|
|
488
|
+
? getAlignmentOptionsConfig(state, intl)
|
|
489
|
+
: [];
|
|
488
490
|
|
|
489
491
|
let cellItems: Array<FloatingToolbarItem<Command>>;
|
|
490
492
|
cellItems = pluginState.isDragAndDropEnabled
|
|
@@ -886,16 +888,21 @@ const highlightColumnsHandler = (
|
|
|
886
888
|
return false;
|
|
887
889
|
};
|
|
888
890
|
|
|
891
|
+
type AlignmentIcon = {
|
|
892
|
+
id?: string;
|
|
893
|
+
value: TableLayout;
|
|
894
|
+
icon: React.ComponentClass<any>;
|
|
895
|
+
};
|
|
896
|
+
|
|
889
897
|
export const getAlignmentOptionsConfig = (
|
|
890
|
-
|
|
898
|
+
editorState: EditorState,
|
|
891
899
|
{ formatMessage }: ToolbarMenuContext,
|
|
892
|
-
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
893
900
|
): Array<FloatingToolbarDropdown<Command>> => {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
}
|
|
901
|
+
const tableObject = findTable(editorState.selection);
|
|
902
|
+
|
|
903
|
+
if (!tableObject) {
|
|
904
|
+
return [];
|
|
905
|
+
}
|
|
899
906
|
|
|
900
907
|
const alignmentIcons: AlignmentIcon[] = [
|
|
901
908
|
{
|
|
@@ -924,13 +931,13 @@ export const getAlignmentOptionsConfig = (
|
|
|
924
931
|
type: 'button',
|
|
925
932
|
icon: icon,
|
|
926
933
|
title: formatMessage(layoutToMessages[value]),
|
|
927
|
-
selected:
|
|
928
|
-
onClick:
|
|
934
|
+
selected: tableObject.node.attrs.layout === value,
|
|
935
|
+
onClick: alignTable(value),
|
|
929
936
|
};
|
|
930
937
|
},
|
|
931
938
|
);
|
|
932
939
|
|
|
933
|
-
const
|
|
940
|
+
const alignmentItemOptions: DropdownOptions<Command> = {
|
|
934
941
|
render: (props) => {
|
|
935
942
|
return (
|
|
936
943
|
<FloatingAlignmentButtons
|
|
@@ -943,28 +950,62 @@ export const getAlignmentOptionsConfig = (
|
|
|
943
950
|
height: 32,
|
|
944
951
|
};
|
|
945
952
|
|
|
953
|
+
const selectedAlignmentIcon = getSelectedAlignmentIcon(
|
|
954
|
+
alignmentIcons,
|
|
955
|
+
tableObject.node,
|
|
956
|
+
);
|
|
957
|
+
|
|
946
958
|
const alignmentToolbarItem: Array<FloatingToolbarDropdown<Command>> = [
|
|
947
959
|
{
|
|
948
960
|
id: 'table-layout',
|
|
949
961
|
testId: 'table-layout-dropdown',
|
|
950
962
|
type: 'dropdown',
|
|
951
|
-
options:
|
|
952
|
-
title: formatMessage(messages.tableAlignmentOptions),
|
|
953
|
-
icon:
|
|
963
|
+
options: alignmentItemOptions,
|
|
964
|
+
title: formatMessage(messages.tableAlignmentOptions),
|
|
965
|
+
icon: selectedAlignmentIcon?.icon,
|
|
954
966
|
},
|
|
955
967
|
];
|
|
956
968
|
|
|
957
969
|
return alignmentToolbarItem;
|
|
958
970
|
};
|
|
959
971
|
|
|
960
|
-
const
|
|
972
|
+
const alignTable = (nextLayoutValue: TableLayout): Command => {
|
|
961
973
|
return (state, dispatch) => {
|
|
962
974
|
const tableObject = findTable(state.selection);
|
|
963
975
|
|
|
964
976
|
if (!tableObject || !dispatch) {
|
|
965
977
|
return false;
|
|
966
978
|
}
|
|
967
|
-
|
|
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);
|
|
968
996
|
return true;
|
|
969
997
|
};
|
|
970
998
|
};
|
|
999
|
+
|
|
1000
|
+
export const getSelectedAlignmentIcon = (
|
|
1001
|
+
alignmentIcons: AlignmentIcon[],
|
|
1002
|
+
selectedNode: PMNode,
|
|
1003
|
+
) => {
|
|
1004
|
+
const selectedAlignment = selectedNode.attrs.layout;
|
|
1005
|
+
|
|
1006
|
+
return alignmentIcons.find(
|
|
1007
|
+
(icon) =>
|
|
1008
|
+
icon.value ===
|
|
1009
|
+
(selectedNode.attrs.layout === 'default' ? 'center' : selectedAlignment),
|
|
1010
|
+
);
|
|
1011
|
+
};
|