@atlaskit/editor-plugin-table 2.5.5 → 2.6.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 +16 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/cjs/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +49 -18
- package/dist/cjs/plugins/table/nodeviews/table.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/es2019/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +48 -19
- package/dist/es2019/plugins/table/nodeviews/table.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +14 -1
- package/dist/esm/plugins/table/nodeviews/TableContainer.js +6 -2
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +50 -19
- package/dist/esm/plugins/table/nodeviews/table.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/scale-table.js +8 -5
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +4 -1
- package/dist/types/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +4 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +1 -0
- package/package.json +2 -2
- package/src/__tests__/unit/nodeviews/TableContainer.tsx +74 -11
- package/src/plugins/table/nodeviews/TableComponent.tsx +19 -1
- package/src/plugins/table/nodeviews/TableContainer.tsx +11 -4
- package/src/plugins/table/nodeviews/TableResizer.tsx +94 -32
- package/src/plugins/table/nodeviews/table.tsx +6 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/scale-table.ts +20 -12
|
@@ -4,17 +4,37 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
4
4
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
5
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import rafSchd from 'raf-schd';
|
|
7
|
+
import { ACTION_SUBJECT, EVENT_TYPE, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
|
|
7
8
|
import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
|
|
8
9
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
9
|
-
import {
|
|
10
|
+
import { TableMap } from '@atlaskit/editor-tables';
|
|
11
|
+
import { COLUMN_MIN_WIDTH, getColgroupChildrenLength, hasTableBeenResized, previewScaleTable, scaleTable } from '../pm-plugins/table-resizing/utils';
|
|
10
12
|
import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
|
|
11
13
|
import { TABLE_HIGHLIGHT_GAP, TABLE_SNAP_GAP } from '../ui/consts';
|
|
14
|
+
import { getTableWidth } from '../utils';
|
|
12
15
|
import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
|
|
13
16
|
import { findClosestSnap } from '../utils/snapping';
|
|
14
17
|
var handles = {
|
|
15
18
|
right: true
|
|
16
19
|
};
|
|
17
20
|
var tableHandleMarginTop = 11;
|
|
21
|
+
var generateResizedPayload = function generateResizedPayload(props) {
|
|
22
|
+
var _props$originalNode$a;
|
|
23
|
+
var tableMap = TableMap.get(props.resizedNode);
|
|
24
|
+
return {
|
|
25
|
+
action: TABLE_ACTION.RESIZED,
|
|
26
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
27
|
+
eventType: EVENT_TYPE.TRACK,
|
|
28
|
+
attributes: {
|
|
29
|
+
newWidth: props.resizedNode.attrs.width,
|
|
30
|
+
prevWidth: (_props$originalNode$a = props.originalNode.attrs.width) !== null && _props$originalNode$a !== void 0 ? _props$originalNode$a : null,
|
|
31
|
+
nodeSize: props.resizedNode.nodeSize,
|
|
32
|
+
totalTableWidth: hasTableBeenResized(props.resizedNode) ? getTableWidth(props.resizedNode) : null,
|
|
33
|
+
totalRowCount: tableMap.height,
|
|
34
|
+
totalColumnCount: tableMap.width
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
18
38
|
export var TableResizer = function TableResizer(_ref) {
|
|
19
39
|
var children = _ref.children,
|
|
20
40
|
width = _ref.width,
|
|
@@ -24,7 +44,8 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
24
44
|
getPos = _ref.getPos,
|
|
25
45
|
node = _ref.node,
|
|
26
46
|
tableRef = _ref.tableRef,
|
|
27
|
-
displayGuideline = _ref.displayGuideline
|
|
47
|
+
displayGuideline = _ref.displayGuideline,
|
|
48
|
+
attachAnalyticsEvent = _ref.attachAnalyticsEvent;
|
|
28
49
|
var currentColumnCount = getColgroupChildrenLength(node);
|
|
29
50
|
var minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
|
|
30
51
|
var tableHeight = tableRef === null || tableRef === void 0 ? void 0 : tableRef.clientHeight;
|
|
@@ -78,6 +99,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
78
99
|
resizing: false
|
|
79
100
|
});
|
|
80
101
|
if (typeof pos === 'number') {
|
|
102
|
+
var _attachAnalyticsEvent;
|
|
81
103
|
tr = tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
|
|
82
104
|
width: newWidth
|
|
83
105
|
}));
|
|
@@ -88,6 +110,11 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
88
110
|
start: pos + 1,
|
|
89
111
|
parentWidth: newWidth
|
|
90
112
|
}, editorView.domAtPos.bind(editorView))(tr);
|
|
113
|
+
var scaledNode = tr.doc.nodeAt(pos);
|
|
114
|
+
(_attachAnalyticsEvent = attachAnalyticsEvent(generateResizedPayload({
|
|
115
|
+
originalNode: node,
|
|
116
|
+
resizedNode: scaledNode
|
|
117
|
+
}))) === null || _attachAnalyticsEvent === void 0 ? void 0 : _attachAnalyticsEvent(tr);
|
|
91
118
|
}
|
|
92
119
|
dispatch(tr);
|
|
93
120
|
|
|
@@ -95,7 +122,26 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
95
122
|
displayGuideline([]);
|
|
96
123
|
updateWidth(newWidth);
|
|
97
124
|
return newWidth;
|
|
98
|
-
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline]);
|
|
125
|
+
}, [updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent]);
|
|
126
|
+
var handleResize = useCallback(function (originalState, delta) {
|
|
127
|
+
var newWidth = originalState.width + delta.width;
|
|
128
|
+
var pos = getPos();
|
|
129
|
+
if (typeof pos !== 'number') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
previewScaleTable(tableRef, {
|
|
133
|
+
node: node,
|
|
134
|
+
prevNode: node,
|
|
135
|
+
start: pos + 1,
|
|
136
|
+
parentWidth: newWidth
|
|
137
|
+
}, editorView.domAtPos.bind(editorView));
|
|
138
|
+
updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
|
|
139
|
+
updateWidth(newWidth);
|
|
140
|
+
return newWidth;
|
|
141
|
+
}, [editorView, getPos, node, tableRef, updateWidth, updateActiveGuidelines]);
|
|
142
|
+
var scheduleResize = useMemo(function () {
|
|
143
|
+
return rafSchd(handleResize);
|
|
144
|
+
}, [handleResize]);
|
|
99
145
|
return /*#__PURE__*/React.createElement(ResizerNext, {
|
|
100
146
|
enable: handles,
|
|
101
147
|
width: width,
|
|
@@ -103,22 +149,7 @@ export var TableResizer = function TableResizer(_ref) {
|
|
|
103
149
|
handleHeightSize: handleHeightSize,
|
|
104
150
|
handleMarginTop: tableHandleMarginTop,
|
|
105
151
|
handleResizeStart: handleResizeStart,
|
|
106
|
-
handleResize:
|
|
107
|
-
var newWidth = originalState.width + delta.width;
|
|
108
|
-
var pos = getPos();
|
|
109
|
-
if (typeof pos !== 'number') {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
previewScaleTable(tableRef, {
|
|
113
|
-
node: node,
|
|
114
|
-
prevNode: node,
|
|
115
|
-
start: pos + 1,
|
|
116
|
-
parentWidth: newWidth
|
|
117
|
-
}, editorView.domAtPos.bind(editorView));
|
|
118
|
-
updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
|
|
119
|
-
updateWidth(newWidth);
|
|
120
|
-
return newWidth;
|
|
121
|
-
}),
|
|
152
|
+
handleResize: scheduleResize,
|
|
122
153
|
handleResizeStop: handleResizeStop,
|
|
123
154
|
resizeRatio: 2,
|
|
124
155
|
minWidth: minColumnWidth,
|
|
@@ -15,6 +15,7 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
15
15
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
16
16
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
17
17
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
18
|
+
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
18
19
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
19
20
|
import { pluginConfig as getPluginConfig } from '../create-plugin-config';
|
|
20
21
|
import { getPluginState } from '../pm-plugins/plugin-factory';
|
|
@@ -29,7 +30,7 @@ var tableAttributes = function tableAttributes(node, options, state, pos) {
|
|
|
29
30
|
// this is to ensure 'responsive' tables (colgroup widths are undefined) become fixed to
|
|
30
31
|
// support screen size adjustments
|
|
31
32
|
var shouldHaveInlineWidth = (options === null || options === void 0 ? void 0 : options.isTableResizingEnabled) && !isTableNested(state, pos);
|
|
32
|
-
var style = shouldHaveInlineWidth ? "width: ".concat(getTableContainerWidth(node), "px") : undefined;
|
|
33
|
+
var style = shouldHaveInlineWidth ? "width: ".concat(node.attrs.isNumberColumnEnabled ? getTableContainerWidth(node) - akEditorTableNumberColumnWidth : getTableContainerWidth(node), "px") : undefined;
|
|
33
34
|
return {
|
|
34
35
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
35
36
|
'data-layout': node.attrs.layout,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
4
5
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
6
|
import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
|
|
6
7
|
import { updateColumnWidths } from '../../../transforms';
|
|
@@ -23,12 +24,13 @@ export var scale = function scale(tableRef, options, domAtPos) {
|
|
|
23
24
|
prevNode = options.prevNode,
|
|
24
25
|
start = options.start,
|
|
25
26
|
isBreakoutEnabled = options.isBreakoutEnabled,
|
|
26
|
-
layoutChanged = options.layoutChanged
|
|
27
|
-
|
|
27
|
+
layoutChanged = options.layoutChanged,
|
|
28
|
+
isTableResizingEnabled = options.isTableResizingEnabled;
|
|
29
|
+
var maxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(node.attrs.layout, containerWidth, {
|
|
28
30
|
isBreakoutEnabled: isBreakoutEnabled
|
|
29
31
|
});
|
|
30
32
|
var prevTableWidth = getTableWidth(prevNode);
|
|
31
|
-
var previousMaxSize = getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
33
|
+
var previousMaxSize = isTableResizingEnabled ? getTableContainerWidth(node) : getLayoutSize(prevNode.attrs.layout, previousContainerWidth, {
|
|
32
34
|
isBreakoutEnabled: isBreakoutEnabled
|
|
33
35
|
});
|
|
34
36
|
var newWidth = maxSize;
|
|
@@ -105,7 +107,9 @@ export var previewScaleTable = function previewScaleTable(tableRef, options, dom
|
|
|
105
107
|
return;
|
|
106
108
|
}
|
|
107
109
|
if (parentWidth) {
|
|
108
|
-
|
|
110
|
+
var isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
|
|
111
|
+
var width = isNumberColumnEnabled ? parentWidth - akEditorTableNumberColumnWidth : parentWidth;
|
|
112
|
+
tableRef.style.width = "".concat(width, "px");
|
|
109
113
|
}
|
|
110
114
|
if (!hasTableBeenResized(node)) {
|
|
111
115
|
return;
|
|
@@ -126,7 +130,6 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos) {
|
|
|
126
130
|
start = options.start,
|
|
127
131
|
parentWidth = options.parentWidth,
|
|
128
132
|
layoutChanged = options.layoutChanged;
|
|
129
|
-
|
|
130
133
|
// If a table has not been resized yet, columns should be auto.
|
|
131
134
|
if (hasTableBeenResized(node) === false) {
|
|
132
135
|
// If its not a re-sized table, we still want to re-create cols
|
package/dist/esm/version.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { Node as PMNode } from 'prosemirror-model';
|
|
3
|
+
import { Transaction } from 'prosemirror-state';
|
|
3
4
|
import { EditorView } from 'prosemirror-view';
|
|
5
|
+
import { TableEventPayload } from '@atlaskit/editor-common/analytics';
|
|
4
6
|
import type { GuidelineConfig } from '@atlaskit/editor-plugin-guideline';
|
|
5
7
|
interface TableResizerProps {
|
|
6
8
|
width: number;
|
|
@@ -11,6 +13,7 @@ interface TableResizerProps {
|
|
|
11
13
|
node: PMNode;
|
|
12
14
|
tableRef: HTMLTableElement;
|
|
13
15
|
displayGuideline: (guideline: GuidelineConfig[]) => boolean;
|
|
16
|
+
attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
|
|
14
17
|
}
|
|
15
|
-
export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
|
|
18
|
+
export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
|
|
16
19
|
export {};
|
|
@@ -12,6 +12,7 @@ export interface ScaleOptions {
|
|
|
12
12
|
layoutChanged?: boolean;
|
|
13
13
|
isBreakoutEnabled?: boolean;
|
|
14
14
|
isFullWidthModeEnabled?: boolean;
|
|
15
|
+
isTableResizingEnabled?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
|
|
17
18
|
export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { Node as PMNode } from 'prosemirror-model';
|
|
3
|
+
import { Transaction } from 'prosemirror-state';
|
|
3
4
|
import { EditorView } from 'prosemirror-view';
|
|
5
|
+
import { TableEventPayload } from '@atlaskit/editor-common/analytics';
|
|
4
6
|
import type { GuidelineConfig } from '@atlaskit/editor-plugin-guideline';
|
|
5
7
|
interface TableResizerProps {
|
|
6
8
|
width: number;
|
|
@@ -11,6 +13,7 @@ interface TableResizerProps {
|
|
|
11
13
|
node: PMNode;
|
|
12
14
|
tableRef: HTMLTableElement;
|
|
13
15
|
displayGuideline: (guideline: GuidelineConfig[]) => boolean;
|
|
16
|
+
attachAnalyticsEvent: (payload: TableEventPayload) => ((tr: Transaction) => boolean) | undefined;
|
|
14
17
|
}
|
|
15
|
-
export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
|
|
18
|
+
export declare const TableResizer: ({ children, width, maxWidth, updateWidth, editorView, getPos, node, tableRef, displayGuideline, attachAnalyticsEvent, }: PropsWithChildren<TableResizerProps>) => JSX.Element;
|
|
16
19
|
export {};
|
|
@@ -12,6 +12,7 @@ export interface ScaleOptions {
|
|
|
12
12
|
layoutChanged?: boolean;
|
|
13
13
|
isBreakoutEnabled?: boolean;
|
|
14
14
|
isFullWidthModeEnabled?: boolean;
|
|
15
|
+
isTableResizingEnabled?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare const scale: (tableRef: HTMLTableElement, options: ScaleOptions, domAtPos: DomAtPos) => ResizeState | undefined;
|
|
17
18
|
export declare const scaleWithParent: (tableRef: HTMLTableElement, parentWidth: number, table: PMNode, start: number, domAtPos: DomAtPos) => ResizeState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.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
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^26.3.0",
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
31
|
+
"@atlaskit/editor-common": "^74.27.0",
|
|
32
32
|
"@atlaskit/editor-palette": "1.5.1",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^0.1.0",
|
|
34
34
|
"@atlaskit/editor-plugin-content-insertion": "^0.0.6",
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { render } from '@testing-library/react';
|
|
3
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
4
4
|
|
|
5
5
|
import { TableAttributes } from '@atlaskit/adf-schema';
|
|
6
|
+
import {
|
|
7
|
+
ACTION_SUBJECT,
|
|
8
|
+
EVENT_TYPE,
|
|
9
|
+
TABLE_ACTION,
|
|
10
|
+
} from '@atlaskit/editor-common/analytics';
|
|
6
11
|
import { akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
7
12
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
8
13
|
import { createEditorFactory } from '@atlaskit/editor-test-helpers/create-editor';
|
|
@@ -43,12 +48,12 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
43
48
|
});
|
|
44
49
|
};
|
|
45
50
|
const createNode = (attrs?: TableAttributes) => {
|
|
46
|
-
const { editorView
|
|
47
|
-
doc(
|
|
51
|
+
const { editorView } = editor(
|
|
52
|
+
doc(table(attrs)(tr(td()(p('{<>}text')), tdEmpty, tdEmpty))),
|
|
48
53
|
);
|
|
49
|
-
const resolvedTable = findTable(
|
|
54
|
+
const resolvedTable = findTable(editorView.state.selection);
|
|
50
55
|
|
|
51
|
-
return resolvedTable!.node;
|
|
56
|
+
return { editorView, node: resolvedTable!.node };
|
|
52
57
|
};
|
|
53
58
|
|
|
54
59
|
describe('show correct container for FF and options', () => {
|
|
@@ -56,7 +61,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
56
61
|
isTableResizingEnabled: boolean,
|
|
57
62
|
isBreakoutEnabled: boolean = true,
|
|
58
63
|
) => {
|
|
59
|
-
const node = createNode();
|
|
64
|
+
const { node, editorView } = createNode();
|
|
60
65
|
|
|
61
66
|
const { container } = render(
|
|
62
67
|
<TableContainer
|
|
@@ -68,7 +73,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
68
73
|
isTableResizingEnabled={isTableResizingEnabled}
|
|
69
74
|
isBreakoutEnabled={isBreakoutEnabled}
|
|
70
75
|
className={''}
|
|
71
|
-
editorView={
|
|
76
|
+
editorView={editorView}
|
|
72
77
|
getPos={() => 1}
|
|
73
78
|
tableRef={{} as any}
|
|
74
79
|
isNested={false}
|
|
@@ -94,7 +99,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
94
99
|
isTableResizingEnabled: boolean,
|
|
95
100
|
isBreakoutEnabled: boolean = true,
|
|
96
101
|
) => {
|
|
97
|
-
const node = createNode();
|
|
102
|
+
const { node, editorView } = createNode();
|
|
98
103
|
|
|
99
104
|
const { container } = render(
|
|
100
105
|
<TableContainer
|
|
@@ -106,7 +111,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
106
111
|
isTableResizingEnabled={isTableResizingEnabled}
|
|
107
112
|
isBreakoutEnabled={isBreakoutEnabled}
|
|
108
113
|
className={''}
|
|
109
|
-
editorView={
|
|
114
|
+
editorView={editorView}
|
|
110
115
|
getPos={() => 1}
|
|
111
116
|
tableRef={{} as any}
|
|
112
117
|
isNested={true}
|
|
@@ -129,7 +134,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
129
134
|
|
|
130
135
|
describe('sets width and margin correctly for resizable container', () => {
|
|
131
136
|
const buildContainer = (attrs: TableAttributes) => {
|
|
132
|
-
const node = createNode(attrs);
|
|
137
|
+
const { node, editorView } = createNode(attrs);
|
|
133
138
|
|
|
134
139
|
const { container } = render(
|
|
135
140
|
<ResizableTableContainer
|
|
@@ -137,7 +142,7 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
137
142
|
lineLength={720}
|
|
138
143
|
node={node}
|
|
139
144
|
className={''}
|
|
140
|
-
editorView={
|
|
145
|
+
editorView={editorView}
|
|
141
146
|
getPos={() => 1}
|
|
142
147
|
tableRef={{} as any}
|
|
143
148
|
/>,
|
|
@@ -154,4 +159,62 @@ describe('table -> nodeviews -> TableContainer.tsx', () => {
|
|
|
154
159
|
expect(style.marginLeft).toBe('-120px');
|
|
155
160
|
});
|
|
156
161
|
});
|
|
162
|
+
|
|
163
|
+
describe('analytics', () => {
|
|
164
|
+
const buildContainer = (attrs: TableAttributes) => {
|
|
165
|
+
const { node, editorView } = createNode(attrs);
|
|
166
|
+
const analyticsMock = jest.fn();
|
|
167
|
+
|
|
168
|
+
const { container } = render(
|
|
169
|
+
<ResizableTableContainer
|
|
170
|
+
containerWidth={1800}
|
|
171
|
+
lineLength={720}
|
|
172
|
+
node={node}
|
|
173
|
+
className={''}
|
|
174
|
+
editorView={editorView}
|
|
175
|
+
getPos={() => 0}
|
|
176
|
+
tableRef={
|
|
177
|
+
{
|
|
178
|
+
querySelector: () => null,
|
|
179
|
+
insertBefore: () => {},
|
|
180
|
+
style: {},
|
|
181
|
+
} as any
|
|
182
|
+
}
|
|
183
|
+
pluginInjectionApi={
|
|
184
|
+
{
|
|
185
|
+
dependencies: {
|
|
186
|
+
analytics: { actions: { attachAnalyticsEvent: analyticsMock } },
|
|
187
|
+
},
|
|
188
|
+
} as any
|
|
189
|
+
}
|
|
190
|
+
/>,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return { container, analyticsMock };
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
test('fires when resizing is finished', async () => {
|
|
197
|
+
const { container, analyticsMock } = buildContainer({ layout: 'wide' });
|
|
198
|
+
|
|
199
|
+
fireEvent.mouseDown(container.querySelector('.resizer-handle-right')!);
|
|
200
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle-right')!);
|
|
201
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle-right')!);
|
|
202
|
+
fireEvent.mouseMove(container.querySelector('.resizer-handle-right')!);
|
|
203
|
+
fireEvent.mouseUp(container.querySelector('.resizer-handle-right')!);
|
|
204
|
+
|
|
205
|
+
expect(analyticsMock).toHaveBeenLastCalledWith({
|
|
206
|
+
action: TABLE_ACTION.RESIZED,
|
|
207
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
208
|
+
eventType: EVENT_TYPE.TRACK,
|
|
209
|
+
attributes: {
|
|
210
|
+
width: undefined, // Can't get the events right to trigger re-resizeable
|
|
211
|
+
prevWidth: null,
|
|
212
|
+
nodeSize: 20,
|
|
213
|
+
totalTableWidth: null,
|
|
214
|
+
totalRowCount: 1,
|
|
215
|
+
totalColumnCount: 3,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
157
220
|
});
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
insertColgroupFromNode as recreateResizeColsByNode,
|
|
32
32
|
scaleTable,
|
|
33
33
|
} from '../pm-plugins/table-resizing/utils';
|
|
34
|
+
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
34
35
|
import { updateControls } from '../pm-plugins/table-resizing/utils/dom';
|
|
35
36
|
import {
|
|
36
37
|
TableCssClassName as ClassName,
|
|
@@ -562,8 +563,24 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
562
563
|
|
|
563
564
|
// If column has been inserted/deleted avoid multi dispatch
|
|
564
565
|
if (shouldScaleTable) {
|
|
565
|
-
this.scaleTable({
|
|
566
|
+
this.scaleTable({
|
|
567
|
+
parentWidth,
|
|
568
|
+
layoutChanged,
|
|
569
|
+
isTableResizingEnabled: options?.isTableResizingEnabled,
|
|
570
|
+
});
|
|
566
571
|
}
|
|
572
|
+
|
|
573
|
+
// only when table resizing is enabled and toggle numbered column to run scaleTable
|
|
574
|
+
if (options?.isTableResizingEnabled && hasNumberedColumnChanged) {
|
|
575
|
+
if (!hasTableBeenResized(prevNode)) {
|
|
576
|
+
this.scaleTable({
|
|
577
|
+
parentWidth,
|
|
578
|
+
layoutChanged,
|
|
579
|
+
isTableResizingEnabled: options?.isTableResizingEnabled,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
567
584
|
this.updateParentWidth(parentWidth);
|
|
568
585
|
}
|
|
569
586
|
|
|
@@ -575,6 +592,7 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
575
592
|
private scaleTable = (scaleOptions: {
|
|
576
593
|
layoutChanged: boolean;
|
|
577
594
|
parentWidth?: number;
|
|
595
|
+
isTableResizingEnabled?: boolean;
|
|
578
596
|
}) => {
|
|
579
597
|
const { view, getNode, getPos, containerWidth, options } = this.props;
|
|
580
598
|
const node = getNode();
|
|
@@ -9,6 +9,7 @@ import classNames from 'classnames';
|
|
|
9
9
|
import { Node as PMNode } from 'prosemirror-model';
|
|
10
10
|
import { EditorView } from 'prosemirror-view';
|
|
11
11
|
|
|
12
|
+
import { TableEventPayload } from '@atlaskit/editor-common/analytics';
|
|
12
13
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
13
14
|
import { calcTableWidth } from '@atlaskit/editor-common/styles';
|
|
14
15
|
import { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
@@ -115,15 +116,20 @@ export const ResizableTableContainer = ({
|
|
|
115
116
|
[pluginInjectionApi, editorView],
|
|
116
117
|
);
|
|
117
118
|
|
|
118
|
-
const
|
|
119
|
+
const attachAnalyticsEvent = useCallback(
|
|
120
|
+
(payload: TableEventPayload) => {
|
|
121
|
+
return pluginInjectionApi?.dependencies?.analytics.actions.attachAnalyticsEvent(
|
|
122
|
+
payload,
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
[pluginInjectionApi],
|
|
126
|
+
);
|
|
119
127
|
|
|
128
|
+
const tableWidth = getTableContainerWidth(node);
|
|
120
129
|
// 76 is currently an accepted padding value considering the spacing for resizer handle
|
|
121
130
|
const responsiveContainerWidth = containerWidth - 76;
|
|
122
|
-
|
|
123
131
|
const width = Math.min(tableWidth, responsiveContainerWidth);
|
|
124
|
-
|
|
125
132
|
marginLeftRef.current = getMarginLeft(lineLength, width);
|
|
126
|
-
|
|
127
133
|
const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
|
|
128
134
|
|
|
129
135
|
return (
|
|
@@ -141,6 +147,7 @@ export const ResizableTableContainer = ({
|
|
|
141
147
|
node={node}
|
|
142
148
|
tableRef={tableRef}
|
|
143
149
|
displayGuideline={displayGuideline}
|
|
150
|
+
attachAnalyticsEvent={attachAnalyticsEvent}
|
|
144
151
|
>
|
|
145
152
|
<InnerContainer className={className} node={node}>
|
|
146
153
|
{children}
|