@atlaskit/editor-plugin-table 1.6.1 → 1.6.3
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/plugins/table/index.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +3 -1
- package/dist/cjs/plugins/table/types.js +1 -0
- package/dist/cjs/plugins/table/ui/FloatingContextualButton/FixedButton.js +133 -0
- package/dist/cjs/plugins/table/ui/FloatingContextualButton/index.js +73 -128
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +3 -1
- package/dist/es2019/plugins/table/types.js +1 -0
- package/dist/es2019/plugins/table/ui/FloatingContextualButton/FixedButton.js +120 -0
- package/dist/es2019/plugins/table/ui/FloatingContextualButton/index.js +76 -108
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +3 -1
- package/dist/esm/plugins/table/types.js +1 -0
- package/dist/esm/plugins/table/ui/FloatingContextualButton/FixedButton.js +118 -0
- package/dist/esm/plugins/table/ui/FloatingContextualButton/index.js +73 -129
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/types.d.ts +1 -0
- package/dist/types/plugins/table/ui/FloatingContextualButton/FixedButton.d.ts +23 -0
- package/dist/types/plugins/table/ui/FloatingContextualButton/index.d.ts +1 -9
- package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/FixedButton.d.ts +23 -0
- package/dist/types-ts4.5/plugins/table/ui/FloatingContextualButton/index.d.ts +1 -9
- package/package.json +5 -4
- package/src/__tests__/playwright/__fixtures__/base-adfs.ts +1486 -0
- package/src/__tests__/playwright/extensions.spec.ts +67 -0
- package/src/__tests__/unit/nodeviews/cell.ts +0 -14
- package/src/__tests__/unit/ui/FixedButton.tsx +214 -0
- package/src/plugins/table/index.tsx +1 -0
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +2 -1
- package/src/plugins/table/types.ts +1 -0
- package/src/plugins/table/ui/FloatingContextualButton/FixedButton.tsx +175 -0
- package/src/plugins/table/ui/FloatingContextualButton/index.tsx +41 -95
|
@@ -8,30 +8,19 @@ import { WrappedComponentProps, injectIntl } from 'react-intl-next';
|
|
|
8
8
|
|
|
9
9
|
import { TableLayout } from '@atlaskit/adf-schema';
|
|
10
10
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
11
|
-
import {
|
|
12
|
-
akEditorFloatingOverlapPanelZIndex,
|
|
13
|
-
akEditorSmallZIndex,
|
|
14
|
-
} from '@atlaskit/editor-shared-styles';
|
|
11
|
+
import { akEditorSmallZIndex } from '@atlaskit/editor-shared-styles';
|
|
15
12
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
16
13
|
|
|
17
14
|
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
18
15
|
|
|
19
|
-
import { closestElement } from '@atlaskit/editor-common/utils';
|
|
20
16
|
import { toggleContextualMenu } from '../../commands';
|
|
21
17
|
import { RowStickyState } from '../../pm-plugins/sticky-headers';
|
|
22
18
|
import { TableCssClassName as ClassName } from '../../types';
|
|
23
19
|
import messages from '../../ui/messages';
|
|
20
|
+
import FixedButton from './FixedButton';
|
|
24
21
|
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
AnalyticsEventPayload,
|
|
28
|
-
CONTENT_COMPONENT,
|
|
29
|
-
} from '@atlaskit/editor-common/analytics';
|
|
30
|
-
import {
|
|
31
|
-
ACTION,
|
|
32
|
-
ACTION_SUBJECT,
|
|
33
|
-
EVENT_TYPE,
|
|
34
|
-
} from '@atlaskit/editor-common/analytics';
|
|
22
|
+
import { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
23
|
+
import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
|
|
35
24
|
import {
|
|
36
25
|
tableFloatingCellButtonStyles,
|
|
37
26
|
tableFloatingCellButtonSelectedStyles,
|
|
@@ -42,6 +31,7 @@ import { ThemeProps } from '@atlaskit/theme/types';
|
|
|
42
31
|
|
|
43
32
|
export interface Props {
|
|
44
33
|
editorView: EditorView;
|
|
34
|
+
tableWrapper?: HTMLElement;
|
|
45
35
|
tableNode?: PMNode;
|
|
46
36
|
targetCellPosition: number;
|
|
47
37
|
isContextualMenuOpen?: boolean;
|
|
@@ -54,58 +44,41 @@ export interface Props {
|
|
|
54
44
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
55
45
|
}
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
Props & WrappedComponentProps,
|
|
59
|
-
any
|
|
60
|
-
> {
|
|
61
|
-
static displayName = 'FloatingContextualButton';
|
|
47
|
+
const BUTTON_OFFSET = 3;
|
|
62
48
|
|
|
63
|
-
|
|
49
|
+
const FloatingContextualButtonInner = React.memo(
|
|
50
|
+
(props: Props & WrappedComponentProps) => {
|
|
64
51
|
const {
|
|
52
|
+
editorView,
|
|
53
|
+
isContextualMenuOpen,
|
|
65
54
|
mountPoint,
|
|
66
55
|
scrollableElement,
|
|
67
|
-
|
|
56
|
+
stickyHeader,
|
|
57
|
+
tableWrapper,
|
|
68
58
|
targetCellPosition,
|
|
69
|
-
isContextualMenuOpen,
|
|
70
59
|
intl: { formatMessage },
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
} = props; // : Props & WrappedComponentProps
|
|
61
|
+
|
|
62
|
+
const handleClick = () => {
|
|
63
|
+
const { state, dispatch } = editorView;
|
|
64
|
+
// Clicking outside the dropdown handles toggling the menu closed
|
|
65
|
+
// (otherwise these two toggles combat each other).
|
|
66
|
+
// In the event a user clicks the chevron button again
|
|
67
|
+
// That will count as clicking outside the dropdown and
|
|
68
|
+
// will be toggled appropriately
|
|
69
|
+
if (!isContextualMenuOpen) {
|
|
70
|
+
toggleContextualMenu()(state, dispatch);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
73
74
|
const domAtPos = editorView.domAtPos.bind(editorView);
|
|
74
75
|
let targetCellRef: Node | undefined;
|
|
75
|
-
|
|
76
|
-
targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
// eslint-disable-next-line no-console
|
|
79
|
-
console.warn(error);
|
|
80
|
-
if (dispatchAnalyticsEvent) {
|
|
81
|
-
const payload: AnalyticsEventPayload = {
|
|
82
|
-
action: ACTION.ERRORED,
|
|
83
|
-
actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
|
|
84
|
-
eventType: EVENT_TYPE.OPERATIONAL,
|
|
85
|
-
attributes: {
|
|
86
|
-
component: CONTENT_COMPONENT.FLOATING_CONTEXTUAL_BUTTON,
|
|
87
|
-
selection: editorView.state.selection.toJSON(),
|
|
88
|
-
position: targetCellPosition,
|
|
89
|
-
docSize: editorView.state.doc.nodeSize,
|
|
90
|
-
error: error instanceof Error ? error.message : String(error),
|
|
91
|
-
},
|
|
92
|
-
nonPrivacySafeAttributes: {
|
|
93
|
-
errorStack: error instanceof Error ? error.stack : undefined,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
dispatchAnalyticsEvent(payload);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
76
|
+
targetCellRef = findDomRefAtPos(targetCellPosition, domAtPos);
|
|
99
77
|
|
|
100
78
|
if (!targetCellRef || !(targetCellRef instanceof HTMLElement)) {
|
|
101
79
|
return null;
|
|
102
80
|
}
|
|
103
81
|
|
|
104
|
-
const tableWrapper = closestElement(
|
|
105
|
-
targetCellRef,
|
|
106
|
-
`.${ClassName.TABLE_NODE_WRAPPER}`,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
82
|
const labelCellOptions = formatMessage(messages.cellOptions);
|
|
110
83
|
|
|
111
84
|
const button = (
|
|
@@ -120,7 +93,7 @@ export class FloatingContextualButtonInner extends React.Component<
|
|
|
120
93
|
className={ClassName.CONTEXTUAL_MENU_BUTTON}
|
|
121
94
|
selected={isContextualMenuOpen}
|
|
122
95
|
title={labelCellOptions}
|
|
123
|
-
onClick={
|
|
96
|
+
onClick={handleClick}
|
|
124
97
|
iconBefore={<ExpandIcon label="" />}
|
|
125
98
|
aria-label={labelCellOptions}
|
|
126
99
|
/>
|
|
@@ -130,24 +103,19 @@ export class FloatingContextualButtonInner extends React.Component<
|
|
|
130
103
|
const parentSticky =
|
|
131
104
|
targetCellRef.parentElement &&
|
|
132
105
|
targetCellRef.parentElement.className.indexOf('sticky') > -1;
|
|
133
|
-
if (
|
|
134
|
-
const pos = targetCellRef.getBoundingClientRect();
|
|
135
|
-
|
|
106
|
+
if (stickyHeader && parentSticky && tableWrapper) {
|
|
136
107
|
return (
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
zIndex: akEditorFloatingOverlapPanelZIndex,
|
|
146
|
-
left: pos.left + targetCellRef.clientWidth - 20 - 3,
|
|
147
|
-
}}
|
|
108
|
+
<FixedButton
|
|
109
|
+
offset={BUTTON_OFFSET}
|
|
110
|
+
stickyHeader={stickyHeader}
|
|
111
|
+
tableWrapper={tableWrapper}
|
|
112
|
+
targetCellPosition={targetCellPosition}
|
|
113
|
+
targetCellRef={targetCellRef}
|
|
114
|
+
mountTo={tableWrapper}
|
|
115
|
+
isContextualMenuOpen={isContextualMenuOpen}
|
|
148
116
|
>
|
|
149
117
|
{button}
|
|
150
|
-
</
|
|
118
|
+
</FixedButton>
|
|
151
119
|
);
|
|
152
120
|
}
|
|
153
121
|
|
|
@@ -159,7 +127,7 @@ export class FloatingContextualButtonInner extends React.Component<
|
|
|
159
127
|
mountTo={tableWrapper || mountPoint}
|
|
160
128
|
boundariesElement={targetCellRef}
|
|
161
129
|
scrollableElement={scrollableElement}
|
|
162
|
-
offset={[
|
|
130
|
+
offset={[BUTTON_OFFSET, -BUTTON_OFFSET]}
|
|
163
131
|
forcePlacement
|
|
164
132
|
allowOutOfBounds
|
|
165
133
|
zIndex={akEditorSmallZIndex}
|
|
@@ -167,30 +135,8 @@ export class FloatingContextualButtonInner extends React.Component<
|
|
|
167
135
|
{button}
|
|
168
136
|
</Popup>
|
|
169
137
|
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
shouldComponentUpdate(nextProps: Props) {
|
|
173
|
-
return (
|
|
174
|
-
this.props.tableNode !== nextProps.tableNode ||
|
|
175
|
-
this.props.targetCellPosition !== nextProps.targetCellPosition ||
|
|
176
|
-
this.props.layout !== nextProps.layout ||
|
|
177
|
-
this.props.isContextualMenuOpen !== nextProps.isContextualMenuOpen ||
|
|
178
|
-
this.props.isNumberColumnEnabled !== nextProps.isNumberColumnEnabled ||
|
|
179
|
-
this.props.stickyHeader !== nextProps.stickyHeader
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
private handleClick = () => {
|
|
183
|
-
const { state, dispatch } = this.props.editorView;
|
|
184
|
-
// Clicking outside the dropdown handles toggling the menu closed
|
|
185
|
-
// (otherwise these two toggles combat each other).
|
|
186
|
-
// In the event a user clicks the chevron button again
|
|
187
|
-
// That will count as clicking outside the dropdown and
|
|
188
|
-
// will be toggled appropriately
|
|
189
|
-
if (!this.props.isContextualMenuOpen) {
|
|
190
|
-
toggleContextualMenu()(state, dispatch);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
138
|
+
},
|
|
139
|
+
);
|
|
194
140
|
|
|
195
141
|
const FloatingContextualButton = injectIntl(FloatingContextualButtonInner);
|
|
196
142
|
|