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