@atlaskit/editor-plugin-table 7.19.0 → 7.19.2
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 +18 -0
- package/dist/cjs/nodeviews/TableComponent.js +7 -2
- package/dist/cjs/nodeviews/TableResizer.js +1 -4
- package/dist/cjs/plugin.js +3 -2
- package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +38 -4
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/cjs/pm-plugins/table-resizing/utils/consts.js +2 -1
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +10 -2
- package/dist/cjs/toolbar.js +4 -1
- package/dist/cjs/utils/alignment.js +9 -1
- package/dist/es2019/nodeviews/TableComponent.js +7 -3
- package/dist/es2019/nodeviews/TableResizer.js +2 -5
- package/dist/es2019/plugin.js +3 -2
- package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +37 -5
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/es2019/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +10 -4
- package/dist/es2019/toolbar.js +4 -1
- package/dist/es2019/utils/alignment.js +7 -1
- package/dist/esm/nodeviews/TableComponent.js +7 -2
- package/dist/esm/nodeviews/TableResizer.js +2 -5
- package/dist/esm/plugin.js +3 -2
- package/dist/esm/pm-plugins/table-resizing/event-handlers.js +38 -5
- package/dist/esm/pm-plugins/table-resizing/plugin.js +2 -2
- package/dist/esm/pm-plugins/table-resizing/utils/consts.js +1 -0
- package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +11 -3
- package/dist/esm/toolbar.js +4 -1
- package/dist/esm/utils/alignment.js +8 -0
- package/dist/types/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/event-handlers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/consts.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +5 -0
- package/package.json +2 -2
- package/src/nodeviews/TableComponent.tsx +18 -7
- package/src/nodeviews/TableResizer.tsx +7 -8
- package/src/plugin.tsx +2 -0
- package/src/pm-plugins/table-resizing/event-handlers.ts +47 -1
- package/src/pm-plugins/table-resizing/plugin.ts +2 -0
- package/src/pm-plugins/table-resizing/utils/consts.ts +1 -0
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +25 -3
- package/src/toolbar.tsx +11 -1
- package/src/utils/alignment.ts +18 -0
|
@@ -19,6 +19,7 @@ import memoizeOne from 'memoize-one';
|
|
|
19
19
|
import rafSchedule from 'raf-schd';
|
|
20
20
|
import { injectIntl } from 'react-intl-next';
|
|
21
21
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
22
|
+
import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
|
|
22
23
|
import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
23
24
|
import { tableMarginSides } from '@atlaskit/editor-common/styles';
|
|
24
25
|
import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
|
|
@@ -157,7 +158,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
157
158
|
if (shouldScaleTable) {
|
|
158
159
|
_this.scaleTable({
|
|
159
160
|
parentWidth: parentWidth
|
|
160
|
-
});
|
|
161
|
+
}, hasNumberedColumnChanged);
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
@@ -165,7 +166,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
165
166
|
if (!hasTableBeenResized(prevNode)) {
|
|
166
167
|
_this.scaleTable({
|
|
167
168
|
parentWidth: node.attrs.width
|
|
168
|
-
});
|
|
169
|
+
}, true);
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
_this.updateParentWidth(parentWidth);
|
|
@@ -176,6 +177,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
176
177
|
});
|
|
177
178
|
// Function gets called when table is nested.
|
|
178
179
|
_defineProperty(_assertThisInitialized(_this), "scaleTable", function (scaleOptions) {
|
|
180
|
+
var isUserTriggered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
179
181
|
var _this$props2 = _this.props,
|
|
180
182
|
view = _this$props2.view,
|
|
181
183
|
getNode = _this$props2.getNode,
|
|
@@ -202,6 +204,9 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
202
204
|
// isTableScalingEnabled doesn't change the behavior of nested tables
|
|
203
205
|
false // shouldUseIncreasedScalingPercent set to false for nested tables
|
|
204
206
|
)(state.tr);
|
|
207
|
+
if (!isUserTriggered) {
|
|
208
|
+
tintDirtyTransaction(tr);
|
|
209
|
+
}
|
|
205
210
|
dispatch(tr);
|
|
206
211
|
});
|
|
207
212
|
_defineProperty(_assertThisInitialized(_this), "setTimerToSendInitialOverflowCaptured", function (isOverflowing) {
|
|
@@ -22,12 +22,11 @@ import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
|
22
22
|
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, previewScaleTable, scaleTable, TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
23
23
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
24
24
|
import { TABLE_GUIDELINE_VISIBLE_ADJUSTMENT, TABLE_HIGHLIGHT_GAP, TABLE_HIGHLIGHT_TOLERANCE, TABLE_SNAP_GAP } from '../ui/consts';
|
|
25
|
-
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment } from '../utils/alignment';
|
|
25
|
+
import { ALIGN_CENTER, ALIGN_START, normaliseAlignment, shouldChangeAlignmentToCenterResized } from '../utils/alignment';
|
|
26
26
|
import { generateResizedPayload, generateResizeFrameRatePayloads, useMeasureFramerate } from '../utils/analytics';
|
|
27
27
|
import { defaultGuidelines, defaultGuidelinesForPreserveTable, PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET } from '../utils/guidelines';
|
|
28
28
|
import { defaultSnappingWidths, defaultTablePreserveSnappingWidths, findClosestSnap, PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET } from '../utils/snapping';
|
|
29
29
|
var RESIZE_STEP_VALUE = 10;
|
|
30
|
-
var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
31
30
|
var handles = {
|
|
32
31
|
right: true
|
|
33
32
|
};
|
|
@@ -164,9 +163,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
164
163
|
} : undefined;
|
|
165
164
|
}, [snappingEnabled, isTableScalingEnabled, excludeGuidelineConfig, containerWidth, lineLength, isFullWidthModeEnabled]);
|
|
166
165
|
var switchToCenterAlignment = useCallback(function (pos, node, newWidth, state, dispatch) {
|
|
167
|
-
if (isTableAlignmentEnabled
|
|
168
|
-
// We don't want to switch alignment in Full-width editor
|
|
169
|
-
isResizing.current) {
|
|
166
|
+
if (shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, node, lineLength, newWidth) && isResizing.current) {
|
|
170
167
|
var _pluginInjectionApi$a;
|
|
171
168
|
var tableNodeWithPos = {
|
|
172
169
|
pos: pos,
|
package/dist/esm/plugin.js
CHANGED
|
@@ -171,12 +171,13 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
171
171
|
tableOptions = _ref5.tableOptions,
|
|
172
172
|
getEditorFeatureFlags = _ref5.getEditorFeatureFlags,
|
|
173
173
|
isTableScalingEnabled = _ref5.isTableScalingEnabled,
|
|
174
|
-
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled
|
|
174
|
+
isNewColumnResizingEnabled = _ref5.isNewColumnResizingEnabled,
|
|
175
|
+
isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled;
|
|
175
176
|
var _pluginConfig = pluginConfig(tableOptions),
|
|
176
177
|
allowColumnResizing = _pluginConfig.allowColumnResizing;
|
|
177
178
|
return allowColumnResizing ? createFlexiResizingPlugin(dispatch, {
|
|
178
179
|
lastColumnResizable: !fullWidthEnabled
|
|
179
|
-
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled) : undefined;
|
|
180
|
+
}, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled || false, isNewColumnResizingEnabled, isTableAlignmentEnabled) : undefined;
|
|
180
181
|
}
|
|
181
182
|
}, {
|
|
182
183
|
name: 'tableEditing',
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
import { ACTION_SUBJECT, CHANGE_ALIGNMENT_REASON, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
2
5
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
4
7
|
import { getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
@@ -7,16 +10,19 @@ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
|
7
10
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
8
11
|
import { updateColumnWidths } from '../../transforms';
|
|
9
12
|
import { getSelectedColumnIndexes, isTableNested } from '../../utils';
|
|
13
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../utils/alignment';
|
|
10
14
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
11
15
|
import { META_KEYS } from '../table-analytics';
|
|
12
16
|
import { evenColumns, setDragging, stopResizing } from './commands';
|
|
13
17
|
import { getPluginState } from './plugin-factory';
|
|
14
18
|
import { currentColWidth, getResizeState, getTableMaxWidth, pointsAtCell, resizeColumn, resizeColumnAndTable, updateControls } from './utils';
|
|
15
|
-
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled) {
|
|
19
|
+
export var handleMouseDown = function handleMouseDown(view, event, localResizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
16
20
|
var state = view.state,
|
|
17
21
|
dispatch = view.dispatch;
|
|
18
22
|
var editorDisabled = !view.editable;
|
|
19
23
|
var domAtPos = view.domAtPos.bind(view);
|
|
24
|
+
var _getEditorContainerWi = getEditorContainerWidth(),
|
|
25
|
+
lineLength = _getEditorContainerWi.lineLength;
|
|
20
26
|
if (editorDisabled || localResizeHandlePos === null || !pointsAtCell(state.doc.resolve(localResizeHandlePos))) {
|
|
21
27
|
return false;
|
|
22
28
|
}
|
|
@@ -127,6 +133,8 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
127
133
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
128
134
|
if (table.eq(originalTable)) {
|
|
129
135
|
var map = TableMap.get(table);
|
|
136
|
+
var totalRowCount = map.height;
|
|
137
|
+
var totalColumnCount = map.width;
|
|
130
138
|
var colIndex = map.colCount($cell.pos - start) + ($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) - 1;
|
|
131
139
|
var selectionRect = getSelectionRect(state.selection);
|
|
132
140
|
var selectedColumns = selectionRect ? getSelectedColumnIndexes(selectionRect) : [];
|
|
@@ -143,9 +151,34 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
143
151
|
// isTableScalingEnabled
|
|
144
152
|
undefined,
|
|
145
153
|
// originalTableWidth
|
|
146
|
-
shouldUseIncreasedScalingPercent);
|
|
154
|
+
shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
147
155
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
148
|
-
|
|
156
|
+
|
|
157
|
+
// If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
|
|
158
|
+
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, originalTable, lineLength, newResizeState.tableWidth);
|
|
159
|
+
if (shouldChangeAlignment) {
|
|
160
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, _objectSpread(_objectSpread({}, table.attrs), {}, {
|
|
161
|
+
width: newResizeState.tableWidth,
|
|
162
|
+
layout: ALIGN_CENTER
|
|
163
|
+
}));
|
|
164
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
165
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
166
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
167
|
+
actionSubjectId: null,
|
|
168
|
+
attributes: {
|
|
169
|
+
tableWidth: newResizeState.tableWidth,
|
|
170
|
+
newAlignment: ALIGN_CENTER,
|
|
171
|
+
previousAlignment: ALIGN_START,
|
|
172
|
+
totalRowCount: totalRowCount,
|
|
173
|
+
totalColumnCount: totalColumnCount,
|
|
174
|
+
inputMethod: INPUT_METHOD.AUTO,
|
|
175
|
+
reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED
|
|
176
|
+
},
|
|
177
|
+
eventType: EVENT_TYPE.TRACK
|
|
178
|
+
})(tr);
|
|
179
|
+
} else {
|
|
180
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
181
|
+
}
|
|
149
182
|
} else {
|
|
150
183
|
var _newResizeState = resizeColumn(resizeState, colIndex, resizedDelta, dom, originalTable, resizingSelectedColumns ? selectedColumns : undefined, _shouldScale, shouldUseIncreasedScalingPercent);
|
|
151
184
|
tr = updateColumnWidths(_newResizeState, table, start)(tr);
|
|
@@ -216,7 +249,7 @@ export var handleMouseDown = function handleMouseDown(view, event, localResizeHa
|
|
|
216
249
|
shouldScale = shouldScale && originalTable.attrs.displayMode !== 'fixed';
|
|
217
250
|
}
|
|
218
251
|
if (isNewColumnResizingEnabled && !isTableNested(state, tablePos)) {
|
|
219
|
-
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent);
|
|
252
|
+
resizeColumnAndTable(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, undefined, shouldUseIncreasedScalingPercent, lineLength, isTableAlignmentEnabled);
|
|
220
253
|
} else {
|
|
221
254
|
resizeColumn(resizeState, colIndex, clientX - dragging.startX, dom, table, undefined, shouldScale, shouldUseIncreasedScalingPercent);
|
|
222
255
|
}
|
|
@@ -8,7 +8,7 @@ import { handleMouseDown } from './event-handlers';
|
|
|
8
8
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
9
9
|
import { pluginKey } from './plugin-key';
|
|
10
10
|
import { getResizeCellPos } from './utils';
|
|
11
|
-
export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled) {
|
|
11
|
+
export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorFeatureFlags, editorAnalyticsAPI, isTableScalingEnabled, isNewColumnResizingEnabled, isTableAlignmentEnabled) {
|
|
12
12
|
var _ref$lastColumnResiza = _ref.lastColumnResizable,
|
|
13
13
|
lastColumnResizable = _ref$lastColumnResiza === void 0 ? true : _ref$lastColumnResiza;
|
|
14
14
|
return new SafePlugin({
|
|
@@ -46,7 +46,7 @@ export function createPlugin(dispatch, _ref, getEditorContainerWidth, getEditorF
|
|
|
46
46
|
isColumnKeyboardResizeStarted = isKeyboardResize;
|
|
47
47
|
}
|
|
48
48
|
if (resizeHandlePos !== null && (!dragging || isColumnKeyboardResizeStarted)) {
|
|
49
|
-
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled)) {
|
|
49
|
+
if (handleMouseDown(view, event, resizeHandlePos, getEditorContainerWidth, getEditorFeatureFlags, isTableScalingEnabled || false, editorAnalyticsAPI, isNewColumnResizingEnabled, isTableAlignmentEnabled)) {
|
|
50
50
|
var _state = view.state,
|
|
51
51
|
_dispatch = view.dispatch;
|
|
52
52
|
return setResizeHandlePos(resizeHandlePos)(_state, _dispatch);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export var TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export var TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export var FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export var MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export var MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
// Used to calculate the width of a table using the Editor width
|
|
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
// Resize a given column by an amount from the current state
|
|
5
5
|
|
|
6
6
|
import { TableCssClassName as ClassName } from '../../../types';
|
|
7
|
-
import { ALIGN_START } from '../../../utils/alignment';
|
|
7
|
+
import { ALIGN_CENTER, ALIGN_START, shouldChangeAlignmentToCenterResized } from '../../../utils/alignment';
|
|
8
8
|
import { getTableContainerElementWidth, getTableScalingPercent } from './misc';
|
|
9
9
|
import { growColumn, shrinkColumn, updateAffectedColumn } from './resize-logic';
|
|
10
10
|
import { updateColgroup } from './resize-state';
|
|
@@ -28,6 +28,8 @@ export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, col
|
|
|
28
28
|
var isTableScalingEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
29
29
|
var originalTableWidth = arguments.length > 7 ? arguments[7] : undefined;
|
|
30
30
|
var shouldUseIncreasedScalingPercent = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
31
|
+
var lineLength = arguments.length > 9 ? arguments[9] : undefined;
|
|
32
|
+
var isTableAlignmentEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
|
|
31
33
|
// TODO: can we use document state, and apply scaling factor?
|
|
32
34
|
var tableWidth = tableRef.clientWidth;
|
|
33
35
|
var tableContainerWidth = (_tableRef$closest = tableRef.closest('.pm-table-container')) === null || _tableRef$closest === void 0 ? void 0 : _tableRef$closest.clientWidth;
|
|
@@ -58,17 +60,20 @@ export var resizeColumnAndTable = function resizeColumnAndTable(resizeState, col
|
|
|
58
60
|
// use the difference in width from affected column to update overall table width
|
|
59
61
|
var delta = newState.cols[colIndex].width - resizeState.cols[colIndex].width;
|
|
60
62
|
if (!isOverflowed) {
|
|
61
|
-
|
|
63
|
+
// If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
|
|
64
|
+
var shouldChangeAlignment = shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, newState.tableWidth + delta);
|
|
65
|
+
shouldChangeAlignment ? updateTablePreview(delta, tableRef, tableNode, ALIGN_CENTER) : updateTablePreview(delta, tableRef, tableNode);
|
|
62
66
|
}
|
|
63
67
|
return _objectSpread(_objectSpread({}, newState), {}, {
|
|
64
68
|
// resizeState.tableWidth sometimes is off by ~3px on load on resized table when !isOverflowed, using resizeState.maxSize instead
|
|
65
69
|
tableWidth: isOverflowed ? tableContainerWidth : resizeState.maxSize + delta
|
|
66
70
|
});
|
|
67
71
|
};
|
|
68
|
-
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode) {
|
|
72
|
+
var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tableNode, tableAligment) {
|
|
69
73
|
var currentWidth = getTableContainerElementWidth(tableNode);
|
|
70
74
|
var resizingContainer = tableRef === null || tableRef === void 0 ? void 0 : tableRef.closest(".".concat(ClassName.TABLE_RESIZER_CONTAINER));
|
|
71
75
|
var resizingItem = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.querySelector('.resizer-item');
|
|
76
|
+
var alignmentContainer = resizingContainer === null || resizingContainer === void 0 ? void 0 : resizingContainer.parentElement;
|
|
72
77
|
if (resizingItem) {
|
|
73
78
|
var newWidth = "".concat(currentWidth + resizeAmount, "px");
|
|
74
79
|
if (tableRef) {
|
|
@@ -76,5 +81,8 @@ var updateTablePreview = function updateTablePreview(resizeAmount, tableRef, tab
|
|
|
76
81
|
}
|
|
77
82
|
resizingContainer.style.width = newWidth;
|
|
78
83
|
resizingItem.style.width = newWidth;
|
|
84
|
+
if (tableAligment && alignmentContainer) {
|
|
85
|
+
alignmentContainer.style.justifyContent = tableAligment;
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
};
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -342,7 +342,10 @@ export var getToolbarConfig = function getToolbarConfig(getEditorContainerWidth,
|
|
|
342
342
|
|
|
343
343
|
// We don't want to show floating toolbar while resizing the table
|
|
344
344
|
var isWidthResizing = tableWidthState === null || tableWidthState === void 0 ? void 0 : tableWidthState.resizing;
|
|
345
|
-
|
|
345
|
+
|
|
346
|
+
// Hide floating toolbar when resizing column and internal column width is on
|
|
347
|
+
var shouldHideToolbarForInternalColumnWidth = Boolean((options === null || options === void 0 ? void 0 : options.isNewColumnResizingEnabled) && resizeState && resizeState.dragging);
|
|
348
|
+
if (tableObject && pluginState.editorHasFocus && !isWidthResizing && !shouldHideToolbarForInternalColumnWidth) {
|
|
346
349
|
var nodeType = state.schema.nodes.table;
|
|
347
350
|
var isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
|
|
348
351
|
var isTableScalingWithFixedColumnWidthsOptionShown = isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FULL_WIDTH_EDITOR_CONTENT_WIDTH } from '../pm-plugins/table-resizing/utils/consts';
|
|
1
2
|
export var ALIGN_START = 'align-start';
|
|
2
3
|
export var ALIGN_CENTER = 'center';
|
|
3
4
|
|
|
@@ -7,4 +8,11 @@ export var ALIGN_CENTER = 'center';
|
|
|
7
8
|
*/
|
|
8
9
|
export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
9
10
|
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* We don't want to switch alignment in Full-width editor
|
|
15
|
+
*/
|
|
16
|
+
export var shouldChangeAlignmentToCenterResized = function shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, tableNode, lineLength, updatedTableWidth) {
|
|
17
|
+
return isTableAlignmentEnabled && tableNode && tableNode.attrs.layout === ALIGN_START && lineLength && updatedTableWidth > lineLength && lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH;
|
|
10
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean) => boolean;
|
|
4
|
+
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean) => boolean;
|
|
@@ -3,4 +3,4 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { ColumnResizingPluginState } from '../../types';
|
|
6
|
-
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
6
|
+
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export declare const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export declare const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export declare const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
export declare const TABLE_EDITOR_MARGIN = 76;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { AlignmentOptions } from '../types';
|
|
3
4
|
export declare const ALIGN_START = "align-start";
|
|
4
5
|
export declare const ALIGN_CENTER = "center";
|
|
@@ -7,3 +8,7 @@ export declare const ALIGN_CENTER = "center";
|
|
|
7
8
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
9
|
*/
|
|
9
10
|
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
|
11
|
+
/**
|
|
12
|
+
* We don't want to switch alignment in Full-width editor
|
|
13
|
+
*/
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean) => boolean;
|
|
4
|
+
export declare const handleMouseDown: (view: EditorView, event: MouseEvent, localResizeHandlePos: number, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, isTableScalingEnabled: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean) => boolean;
|
|
@@ -3,4 +3,4 @@ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { ColumnResizingPluginState } from '../../types';
|
|
6
|
-
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
6
|
+
export declare function createPlugin(dispatch: Dispatch<ColumnResizingPluginState>, { lastColumnResizable }: ColumnResizingPluginState, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, editorAnalyticsAPI?: EditorAnalyticsAPI, isTableScalingEnabled?: boolean, isNewColumnResizingEnabled?: boolean, isTableAlignmentEnabled?: boolean): SafePlugin<ColumnResizingPluginState>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export declare const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export declare const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export declare const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export declare const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export declare const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
export declare const TABLE_EDITOR_MARGIN = 76;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { ResizeState } from './types';
|
|
3
3
|
export declare const resizeColumn: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement | null, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
-
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean) => ResizeState;
|
|
4
|
+
export declare const resizeColumnAndTable: (resizeState: ResizeState, colIndex: number, amount: number, tableRef: HTMLElement, tableNode: PmNode, selectedColumns?: number[], isTableScalingEnabled?: boolean, originalTableWidth?: number, shouldUseIncreasedScalingPercent?: boolean, lineLength?: number, isTableAlignmentEnabled?: boolean) => ResizeState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { AlignmentOptions } from '../types';
|
|
3
4
|
export declare const ALIGN_START = "align-start";
|
|
4
5
|
export declare const ALIGN_CENTER = "center";
|
|
@@ -7,3 +8,7 @@ export declare const ALIGN_CENTER = "center";
|
|
|
7
8
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
9
|
*/
|
|
9
10
|
export declare const normaliseAlignment: (layout: TableLayout) => AlignmentOptions;
|
|
11
|
+
/**
|
|
12
|
+
* We don't want to switch alignment in Full-width editor
|
|
13
|
+
*/
|
|
14
|
+
export declare const shouldChangeAlignmentToCenterResized: (isTableAlignmentEnabled: boolean | undefined, tableNode: PmNode, lineLength: number | undefined, updatedTableWidth: number) => boolean | 0 | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.19.
|
|
3
|
+
"version": "7.19.2",
|
|
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": "^38.0.0",
|
|
32
32
|
"@atlaskit/button": "^18.0.0",
|
|
33
33
|
"@atlaskit/custom-steps": "^0.4.0",
|
|
34
|
-
"@atlaskit/editor-common": "^83.
|
|
34
|
+
"@atlaskit/editor-common": "^83.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.4.0",
|
|
@@ -10,6 +10,7 @@ import { injectIntl } from 'react-intl-next';
|
|
|
10
10
|
import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
11
11
|
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
12
12
|
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
13
|
+
import { tintDirtyTransaction } from '@atlaskit/editor-common/collab';
|
|
13
14
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
14
15
|
import { getParentNodeWidth, getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
15
16
|
import { tableMarginSides } from '@atlaskit/editor-common/styles';
|
|
@@ -966,17 +967,23 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
966
967
|
|
|
967
968
|
// If column has been inserted/deleted avoid multi dispatch
|
|
968
969
|
if (shouldScaleTable) {
|
|
969
|
-
this.scaleTable(
|
|
970
|
-
|
|
971
|
-
|
|
970
|
+
this.scaleTable(
|
|
971
|
+
{
|
|
972
|
+
parentWidth,
|
|
973
|
+
},
|
|
974
|
+
hasNumberedColumnChanged,
|
|
975
|
+
);
|
|
972
976
|
}
|
|
973
977
|
|
|
974
978
|
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
975
979
|
if (options?.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
976
980
|
if (!hasTableBeenResized(prevNode)) {
|
|
977
|
-
this.scaleTable(
|
|
978
|
-
|
|
979
|
-
|
|
981
|
+
this.scaleTable(
|
|
982
|
+
{
|
|
983
|
+
parentWidth: node.attrs.width,
|
|
984
|
+
},
|
|
985
|
+
true,
|
|
986
|
+
);
|
|
980
987
|
}
|
|
981
988
|
}
|
|
982
989
|
|
|
@@ -989,7 +996,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
989
996
|
};
|
|
990
997
|
|
|
991
998
|
// Function gets called when table is nested.
|
|
992
|
-
private scaleTable = (scaleOptions: { parentWidth?: number }) => {
|
|
999
|
+
private scaleTable = (scaleOptions: { parentWidth?: number }, isUserTriggered = false) => {
|
|
993
1000
|
const { view, getNode, getPos, containerWidth, options } = this.props;
|
|
994
1001
|
const node = getNode();
|
|
995
1002
|
const { state, dispatch } = view;
|
|
@@ -1019,6 +1026,10 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
1019
1026
|
false, // shouldUseIncreasedScalingPercent set to false for nested tables
|
|
1020
1027
|
)(state.tr);
|
|
1021
1028
|
|
|
1029
|
+
if (!isUserTriggered) {
|
|
1030
|
+
tintDirtyTransaction(tr);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1022
1033
|
dispatch(tr);
|
|
1023
1034
|
};
|
|
1024
1035
|
|
|
@@ -45,7 +45,12 @@ import {
|
|
|
45
45
|
TABLE_HIGHLIGHT_TOLERANCE,
|
|
46
46
|
TABLE_SNAP_GAP,
|
|
47
47
|
} from '../ui/consts';
|
|
48
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
ALIGN_CENTER,
|
|
50
|
+
ALIGN_START,
|
|
51
|
+
normaliseAlignment,
|
|
52
|
+
shouldChangeAlignmentToCenterResized,
|
|
53
|
+
} from '../utils/alignment';
|
|
49
54
|
import {
|
|
50
55
|
generateResizedPayload,
|
|
51
56
|
generateResizeFrameRatePayloads,
|
|
@@ -94,8 +99,6 @@ type ResizerNextHandler = React.ElementRef<typeof ResizerNext>;
|
|
|
94
99
|
|
|
95
100
|
const RESIZE_STEP_VALUE = 10;
|
|
96
101
|
|
|
97
|
-
const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
98
|
-
|
|
99
102
|
const handles = { right: true };
|
|
100
103
|
const handleStyles = {
|
|
101
104
|
right: {
|
|
@@ -296,11 +299,7 @@ export const TableResizer = ({
|
|
|
296
299
|
dispatch: ((tr: Transaction) => void) | undefined,
|
|
297
300
|
) => {
|
|
298
301
|
if (
|
|
299
|
-
isTableAlignmentEnabled &&
|
|
300
|
-
node &&
|
|
301
|
-
node.attrs.layout === ALIGN_START &&
|
|
302
|
-
newWidth > lineLength &&
|
|
303
|
-
lineLength < FULL_WIDTH_EDITOR_CONTENT_WIDTH && // We don't want to switch alignment in Full-width editor
|
|
302
|
+
shouldChangeAlignmentToCenterResized(isTableAlignmentEnabled, node, lineLength, newWidth) &&
|
|
304
303
|
isResizing.current
|
|
305
304
|
) {
|
|
306
305
|
const tableNodeWithPos = { pos, node };
|
package/src/plugin.tsx
CHANGED
|
@@ -303,6 +303,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
303
303
|
getEditorFeatureFlags,
|
|
304
304
|
isTableScalingEnabled,
|
|
305
305
|
isNewColumnResizingEnabled,
|
|
306
|
+
isTableAlignmentEnabled,
|
|
306
307
|
} = options || ({} as TablePluginOptions);
|
|
307
308
|
const { allowColumnResizing } = pluginConfig(tableOptions);
|
|
308
309
|
return allowColumnResizing
|
|
@@ -316,6 +317,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
316
317
|
editorAnalyticsAPI,
|
|
317
318
|
isTableScalingEnabled || false,
|
|
318
319
|
isNewColumnResizingEnabled,
|
|
320
|
+
isTableAlignmentEnabled,
|
|
319
321
|
)
|
|
320
322
|
: undefined;
|
|
321
323
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CellAttributes } from '@atlaskit/adf-schema';
|
|
2
2
|
import {
|
|
3
3
|
ACTION_SUBJECT,
|
|
4
|
+
CHANGE_ALIGNMENT_REASON,
|
|
4
5
|
EVENT_TYPE,
|
|
5
6
|
INPUT_METHOD,
|
|
6
7
|
TABLE_ACTION,
|
|
@@ -18,6 +19,11 @@ import { stopKeyboardColumnResizing } from '../../commands/column-resize';
|
|
|
18
19
|
import { updateResizeHandleDecorations } from '../../commands/misc';
|
|
19
20
|
import { updateColumnWidths } from '../../transforms';
|
|
20
21
|
import { getSelectedColumnIndexes, isTableNested } from '../../utils';
|
|
22
|
+
import {
|
|
23
|
+
ALIGN_CENTER,
|
|
24
|
+
ALIGN_START,
|
|
25
|
+
shouldChangeAlignmentToCenterResized,
|
|
26
|
+
} from '../../utils/alignment';
|
|
21
27
|
import { getPluginState as getTablePluginState } from '../plugin-factory';
|
|
22
28
|
import { META_KEYS } from '../table-analytics';
|
|
23
29
|
|
|
@@ -42,10 +48,12 @@ export const handleMouseDown = (
|
|
|
42
48
|
isTableScalingEnabled: boolean,
|
|
43
49
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
44
50
|
isNewColumnResizingEnabled?: boolean,
|
|
51
|
+
isTableAlignmentEnabled?: boolean,
|
|
45
52
|
): boolean => {
|
|
46
53
|
const { state, dispatch } = view;
|
|
47
54
|
const editorDisabled = !view.editable;
|
|
48
55
|
const domAtPos = view.domAtPos.bind(view);
|
|
56
|
+
const { lineLength } = getEditorContainerWidth();
|
|
49
57
|
|
|
50
58
|
if (
|
|
51
59
|
editorDisabled ||
|
|
@@ -171,6 +179,8 @@ export const handleMouseDown = (
|
|
|
171
179
|
// There may be a more elegant solution to this, to avoid a jarring experience.
|
|
172
180
|
if (table.eq(originalTable)) {
|
|
173
181
|
const map = TableMap.get(table);
|
|
182
|
+
const totalRowCount = map.height;
|
|
183
|
+
const totalColumnCount = map.width;
|
|
174
184
|
const colIndex =
|
|
175
185
|
map.colCount($cell.pos - start) +
|
|
176
186
|
($cell.nodeAfter ? $cell.nodeAfter.attrs.colspan : 1) -
|
|
@@ -202,9 +212,43 @@ export const handleMouseDown = (
|
|
|
202
212
|
shouldScale, // isTableScalingEnabled
|
|
203
213
|
undefined, // originalTableWidth
|
|
204
214
|
shouldUseIncreasedScalingPercent,
|
|
215
|
+
lineLength,
|
|
216
|
+
isTableAlignmentEnabled,
|
|
205
217
|
);
|
|
206
218
|
tr = updateColumnWidths(newResizeState, table, start)(tr);
|
|
207
|
-
|
|
219
|
+
|
|
220
|
+
// If the table is aligned to the start and the table width is greater than the line length, we should change the alignment to center
|
|
221
|
+
const shouldChangeAlignment = shouldChangeAlignmentToCenterResized(
|
|
222
|
+
isTableAlignmentEnabled,
|
|
223
|
+
originalTable,
|
|
224
|
+
lineLength,
|
|
225
|
+
newResizeState.tableWidth,
|
|
226
|
+
);
|
|
227
|
+
if (shouldChangeAlignment) {
|
|
228
|
+
tr = tr.setNodeMarkup(start - 1, state.schema.nodes.table, {
|
|
229
|
+
...table.attrs,
|
|
230
|
+
width: newResizeState.tableWidth,
|
|
231
|
+
layout: ALIGN_CENTER,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
235
|
+
action: TABLE_ACTION.CHANGED_ALIGNMENT,
|
|
236
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
237
|
+
actionSubjectId: null,
|
|
238
|
+
attributes: {
|
|
239
|
+
tableWidth: newResizeState.tableWidth,
|
|
240
|
+
newAlignment: ALIGN_CENTER,
|
|
241
|
+
previousAlignment: ALIGN_START,
|
|
242
|
+
totalRowCount: totalRowCount,
|
|
243
|
+
totalColumnCount: totalColumnCount,
|
|
244
|
+
inputMethod: INPUT_METHOD.AUTO,
|
|
245
|
+
reason: CHANGE_ALIGNMENT_REASON.TABLE_COLUMN_RESIZED,
|
|
246
|
+
},
|
|
247
|
+
eventType: EVENT_TYPE.TRACK,
|
|
248
|
+
})(tr);
|
|
249
|
+
} else {
|
|
250
|
+
tr.setNodeAttribute(start - 1, 'width', newResizeState.tableWidth);
|
|
251
|
+
}
|
|
208
252
|
} else {
|
|
209
253
|
const newResizeState = resizeColumn(
|
|
210
254
|
resizeState,
|
|
@@ -304,6 +348,8 @@ export const handleMouseDown = (
|
|
|
304
348
|
shouldScale,
|
|
305
349
|
undefined,
|
|
306
350
|
shouldUseIncreasedScalingPercent,
|
|
351
|
+
lineLength,
|
|
352
|
+
isTableAlignmentEnabled,
|
|
307
353
|
);
|
|
308
354
|
} else {
|
|
309
355
|
resizeColumn(
|
|
@@ -23,6 +23,7 @@ export function createPlugin(
|
|
|
23
23
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
24
24
|
isTableScalingEnabled?: boolean,
|
|
25
25
|
isNewColumnResizingEnabled?: boolean,
|
|
26
|
+
isTableAlignmentEnabled?: boolean,
|
|
26
27
|
) {
|
|
27
28
|
return new SafePlugin({
|
|
28
29
|
key: pluginKey,
|
|
@@ -74,6 +75,7 @@ export function createPlugin(
|
|
|
74
75
|
isTableScalingEnabled || false,
|
|
75
76
|
editorAnalyticsAPI,
|
|
76
77
|
isNewColumnResizingEnabled,
|
|
78
|
+
isTableAlignmentEnabled,
|
|
77
79
|
)
|
|
78
80
|
) {
|
|
79
81
|
const { state, dispatch } = view;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const COLUMN_MIN_WIDTH = 48;
|
|
2
2
|
export const TABLE_DEFAULT_WIDTH = 760;
|
|
3
3
|
export const TABLE_MAX_WIDTH = 1800;
|
|
4
|
+
export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
|
|
4
5
|
export const MAX_SCALING_PERCENT = 0.3;
|
|
5
6
|
export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
|
|
6
7
|
// Used to calculate the width of a table using the Editor width
|