@atlaskit/editor-plugin-table 7.6.14 → 7.7.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/commands/misc.js +0 -2
  3. package/dist/cjs/nodeviews/OverflowShadowsObserver.js +1 -3
  4. package/dist/cjs/nodeviews/TableComponent.js +3 -18
  5. package/dist/cjs/nodeviews/TableContainer.js +2 -18
  6. package/dist/cjs/nodeviews/table.js +0 -2
  7. package/dist/cjs/plugin.js +3 -20
  8. package/dist/cjs/pm-plugins/main.js +1 -2
  9. package/dist/cjs/pm-plugins/table-resizing/event-handlers.js +7 -21
  10. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +32 -57
  11. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +1 -2
  12. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +16 -28
  13. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +2 -12
  14. package/dist/cjs/reducer.js +0 -2
  15. package/dist/cjs/transforms/column-width.js +3 -5
  16. package/dist/cjs/types.js +0 -1
  17. package/dist/cjs/ui/ColumnResizeWidget/index.js +5 -1
  18. package/dist/cjs/ui/common-styles.js +5 -12
  19. package/dist/cjs/ui/ui-styles.js +7 -12
  20. package/dist/cjs/utils/index.js +0 -6
  21. package/dist/cjs/utils/nodes.js +5 -18
  22. package/dist/es2019/commands/misc.js +0 -2
  23. package/dist/es2019/nodeviews/OverflowShadowsObserver.js +1 -3
  24. package/dist/es2019/nodeviews/TableComponent.js +3 -18
  25. package/dist/es2019/nodeviews/TableContainer.js +1 -16
  26. package/dist/es2019/nodeviews/table.js +0 -2
  27. package/dist/es2019/plugin.js +5 -24
  28. package/dist/es2019/pm-plugins/main.js +1 -2
  29. package/dist/es2019/pm-plugins/table-resizing/event-handlers.js +8 -22
  30. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +30 -53
  31. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +1 -2
  32. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +14 -24
  33. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +2 -12
  34. package/dist/es2019/reducer.js +0 -5
  35. package/dist/es2019/transforms/column-width.js +3 -5
  36. package/dist/es2019/types.js +0 -1
  37. package/dist/es2019/ui/ColumnResizeWidget/index.js +5 -1
  38. package/dist/es2019/ui/common-styles.js +15 -46
  39. package/dist/es2019/ui/ui-styles.js +34 -41
  40. package/dist/es2019/utils/index.js +1 -1
  41. package/dist/es2019/utils/nodes.js +0 -15
  42. package/dist/esm/commands/misc.js +0 -2
  43. package/dist/esm/nodeviews/OverflowShadowsObserver.js +1 -3
  44. package/dist/esm/nodeviews/TableComponent.js +3 -18
  45. package/dist/esm/nodeviews/TableContainer.js +2 -18
  46. package/dist/esm/nodeviews/table.js +0 -2
  47. package/dist/esm/plugin.js +5 -22
  48. package/dist/esm/pm-plugins/main.js +1 -2
  49. package/dist/esm/pm-plugins/table-resizing/event-handlers.js +8 -22
  50. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +32 -57
  51. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +1 -2
  52. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +16 -28
  53. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +2 -12
  54. package/dist/esm/reducer.js +0 -2
  55. package/dist/esm/transforms/column-width.js +3 -5
  56. package/dist/esm/types.js +0 -1
  57. package/dist/esm/ui/ColumnResizeWidget/index.js +5 -1
  58. package/dist/esm/ui/common-styles.js +6 -13
  59. package/dist/esm/ui/ui-styles.js +7 -12
  60. package/dist/esm/utils/index.js +1 -1
  61. package/dist/esm/utils/nodes.js +0 -13
  62. package/dist/types/nodeviews/TableContainer.d.ts +1 -2
  63. package/dist/types/nodeviews/types.d.ts +0 -1
  64. package/dist/types/plugin.d.ts +0 -1
  65. package/dist/types/pm-plugins/main.d.ts +1 -1
  66. package/dist/types/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -1
  67. package/dist/types/types.d.ts +0 -9
  68. package/dist/types/ui/FloatingContextualButton/index.d.ts +0 -2
  69. package/dist/types/utils/index.d.ts +1 -1
  70. package/dist/types/utils/nodes.d.ts +0 -1
  71. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +1 -2
  72. package/dist/types-ts4.5/nodeviews/types.d.ts +0 -1
  73. package/dist/types-ts4.5/plugin.d.ts +0 -1
  74. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  75. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -1
  76. package/dist/types-ts4.5/types.d.ts +0 -9
  77. package/dist/types-ts4.5/ui/FloatingContextualButton/index.d.ts +0 -2
  78. package/dist/types-ts4.5/utils/index.d.ts +1 -1
  79. package/dist/types-ts4.5/utils/nodes.d.ts +0 -1
  80. package/package.json +2 -5
  81. package/src/commands/misc.ts +0 -2
  82. package/src/nodeviews/OverflowShadowsObserver.ts +1 -6
  83. package/src/nodeviews/TableComponent.tsx +2 -25
  84. package/src/nodeviews/TableContainer.tsx +2 -26
  85. package/src/nodeviews/table.tsx +0 -2
  86. package/src/nodeviews/types.ts +0 -1
  87. package/src/plugin.tsx +4 -43
  88. package/src/pm-plugins/main.ts +0 -2
  89. package/src/pm-plugins/table-resizing/event-handlers.ts +8 -37
  90. package/src/pm-plugins/table-resizing/utils/colgroup.ts +40 -61
  91. package/src/pm-plugins/table-resizing/utils/misc.ts +4 -6
  92. package/src/pm-plugins/table-resizing/utils/resize-state.ts +18 -29
  93. package/src/pm-plugins/table-resizing/utils/scale-table.ts +2 -13
  94. package/src/reducer.ts +0 -3
  95. package/src/transforms/column-width.ts +2 -10
  96. package/src/types.ts +0 -8
  97. package/src/ui/ColumnResizeWidget/index.tsx +10 -1
  98. package/src/ui/FloatingContextualButton/index.tsx +0 -2
  99. package/src/ui/common-styles.ts +15 -53
  100. package/src/ui/ui-styles.ts +34 -47
  101. package/src/utils/index.ts +0 -1
  102. package/src/utils/nodes.ts +0 -23
  103. package/dist/cjs/ui/LayoutButton/index.js +0 -206
  104. package/dist/es2019/ui/LayoutButton/index.js +0 -168
  105. package/dist/esm/ui/LayoutButton/index.js +0 -196
  106. package/dist/types/ui/LayoutButton/index.d.ts +0 -21
  107. package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +0 -21
  108. package/src/ui/LayoutButton/index.tsx +0 -217
@@ -1,217 +0,0 @@
1
- import React, { createRef } from 'react';
2
-
3
- import classnames from 'classnames';
4
- import type { WrappedComponentProps } from 'react-intl-next';
5
- import { injectIntl } from 'react-intl-next';
6
-
7
- import type { TableLayout } from '@atlaskit/adf-schema';
8
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
9
- import commonMessages from '@atlaskit/editor-common/messages';
10
- import { Popup } from '@atlaskit/editor-common/ui';
11
- import type { PopupPosition } from '@atlaskit/editor-common/ui';
12
- import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
13
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
14
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
15
- import CollapseIcon from '@atlaskit/icon/glyph/editor/collapse';
16
- import ExpandIcon from '@atlaskit/icon/glyph/editor/expand';
17
-
18
- import { toggleTableLayoutWithAnalytics } from '../../commands-with-analytics';
19
- import type { RowStickyState } from '../../pm-plugins/sticky-headers';
20
- import { TableCssClassName as ClassName } from '../../types';
21
-
22
- export interface Props {
23
- editorView: EditorView;
24
- targetRef?: HTMLElement;
25
- mountPoint?: HTMLElement;
26
- boundariesElement?: HTMLElement;
27
- scrollableElement?: HTMLElement;
28
- isResizing?: boolean;
29
- layout?: TableLayout;
30
- stickyHeader?: RowStickyState;
31
- editorAnalyticsAPI?: EditorAnalyticsAPI;
32
- }
33
-
34
- const addPopupOffset = (pos: PopupPosition) => ({
35
- ...pos,
36
-
37
- // add 12 pixels to align y position with
38
- //the columns controls
39
- top: pos.top ? pos.top + 12 : undefined,
40
- });
41
-
42
- const getMessage = (layout: TableLayout) => {
43
- switch (layout) {
44
- case 'default':
45
- return commonMessages.layoutWide;
46
- case 'wide':
47
- return commonMessages.layoutFullWidth;
48
- default:
49
- return commonMessages.layoutFixedWidth;
50
- }
51
- };
52
-
53
- class LayoutButton extends React.Component<Props & WrappedComponentProps, any> {
54
- static displayName = 'LayoutButton';
55
- private stickyButtonRef = createRef<HTMLDivElement>();
56
-
57
- private resizeObserver: ResizeObserver = new ResizeObserver((entries) => {
58
- entries.forEach(() => {
59
- const resizeButton = this.stickyButtonRef.current;
60
- const tableWrapper = this.props.targetRef;
61
- if (resizeButton && tableWrapper) {
62
- const clientRect = tableWrapper.getBoundingClientRect();
63
- resizeButton.style.left = `${clientRect.right}px`;
64
- }
65
- });
66
- });
67
-
68
- getTitle() {
69
- const {
70
- intl: { formatMessage },
71
- layout = 'default',
72
- } = this.props;
73
- return formatMessage(getMessage(layout));
74
- }
75
-
76
- toolbarButton() {
77
- const { isResizing, layout = 'default' } = this.props;
78
- const title = this.getTitle();
79
-
80
- return (
81
- <div
82
- className={classnames(ClassName.LAYOUT_BUTTON, {
83
- [ClassName.IS_RESIZING]: isResizing,
84
- })}
85
- >
86
- <ToolbarButton
87
- title={title}
88
- onClick={this.handleClick}
89
- iconBefore={
90
- layout === 'full-width' ? (
91
- <CollapseIcon label={title} />
92
- ) : (
93
- <ExpandIcon label={title} />
94
- )
95
- }
96
- />
97
- </div>
98
- );
99
- }
100
-
101
- getStickyTargetRef(pos: number): Node | null {
102
- const { editorView } = this.props;
103
- const domAtPos = editorView.domAtPos.bind(editorView);
104
- const node = findDomRefAtPos(pos, domAtPos) as HTMLElement;
105
- return node.dataset['headerRow'] && node.classList.contains('sticky')
106
- ? node
107
- : null;
108
- }
109
-
110
- renderSticky(button: JSX.Element, targetRef: Node, tableRef: Node) {
111
- const title = this.getTitle();
112
-
113
- if (
114
- !(targetRef instanceof HTMLElement) ||
115
- !(tableRef instanceof HTMLElement)
116
- ) {
117
- return null;
118
- }
119
- const pos = targetRef.getBoundingClientRect();
120
- const tablePos = tableRef.getBoundingClientRect();
121
-
122
- return (
123
- <div
124
- ref={this.stickyButtonRef}
125
- aria-label={title}
126
- style={{
127
- position: 'fixed',
128
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
129
- top: pos.top + 22,
130
- // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
131
- left: tablePos.right,
132
- }}
133
- >
134
- {button}
135
- </div>
136
- );
137
- }
138
-
139
- renderPopup(button: JSX.Element) {
140
- const { mountPoint, boundariesElement, scrollableElement, targetRef } =
141
- this.props;
142
-
143
- if (!targetRef) {
144
- return null;
145
- }
146
-
147
- const title = this.getTitle();
148
-
149
- return (
150
- <Popup
151
- ariaLabel={title}
152
- target={targetRef}
153
- alignY="start"
154
- alignX="end"
155
- onPositionCalculated={addPopupOffset}
156
- stick={true}
157
- mountTo={mountPoint}
158
- boundariesElement={boundariesElement}
159
- scrollableElement={scrollableElement}
160
- forcePlacement={true}
161
- >
162
- {button}
163
- </Popup>
164
- );
165
- }
166
-
167
- render() {
168
- const { stickyHeader } = this.props;
169
- const button = this.toolbarButton();
170
-
171
- const stickyTargetRef =
172
- stickyHeader && stickyHeader.sticky && stickyHeader.pos
173
- ? this.getStickyTargetRef(stickyHeader.pos)
174
- : null;
175
- if (stickyTargetRef && this.props.targetRef) {
176
- return this.renderSticky(button, stickyTargetRef, this.props.targetRef);
177
- } else {
178
- return this.renderPopup(button);
179
- }
180
- }
181
-
182
- componentDidMount() {
183
- const dom = this.props.editorView.dom;
184
- const scrollPanel = dom.closest('.fabric-editor-popup-scroll-parent');
185
- if (scrollPanel instanceof HTMLElement) {
186
- this.resizeObserver.observe(scrollPanel);
187
- }
188
- }
189
-
190
- componentWillUnmount() {
191
- const dom = this.props.editorView.dom;
192
- const scrollPanel = dom.closest('.fabric-editor-popup-scroll-parent');
193
- if (scrollPanel instanceof HTMLElement) {
194
- this.resizeObserver.unobserve(scrollPanel);
195
- }
196
- }
197
-
198
- shouldComponentUpdate(nextProps: Props) {
199
- const { targetRef, layout, isResizing, stickyHeader } = this.props;
200
- return (
201
- stickyHeader !== nextProps.stickyHeader ||
202
- targetRef !== nextProps.targetRef ||
203
- layout !== nextProps.layout ||
204
- isResizing !== nextProps.isResizing
205
- );
206
- }
207
-
208
- private handleClick = () => {
209
- const { state, dispatch } = this.props.editorView;
210
- toggleTableLayoutWithAnalytics(this.props.editorAnalyticsAPI)(
211
- state,
212
- dispatch,
213
- );
214
- };
215
- }
216
-
217
- export default injectIntl(LayoutButton);