@atlaskit/editor-plugin-table 2.1.7 → 2.2.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 (132) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/table/handlers.js +1 -0
  3. package/dist/cjs/plugins/table/index.js +1 -1
  4. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +4 -2
  5. package/dist/cjs/plugins/table/nodeviews/TableContainer.js +50 -47
  6. package/dist/cjs/plugins/table/nodeviews/TableResizer.js +64 -28
  7. package/dist/cjs/plugins/table/nodeviews/table.js +5 -3
  8. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +2 -0
  9. package/dist/cjs/plugins/table/pm-plugins/main.js +2 -2
  10. package/dist/cjs/plugins/table/pm-plugins/table-resizing/plugin-factory.js +1 -1
  11. package/dist/cjs/plugins/table/ui/consts.js +6 -2
  12. package/dist/cjs/plugins/table/utils/collapse.js +2 -0
  13. package/dist/cjs/plugins/table/utils/decoration.js +2 -0
  14. package/dist/cjs/plugins/table/utils/guidelines.js +12 -0
  15. package/dist/cjs/plugins/table/utils/snapping.js +37 -0
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/plugins/table/handlers.js +1 -0
  18. package/dist/es2019/plugins/table/index.js +1 -1
  19. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +4 -2
  20. package/dist/es2019/plugins/table/nodeviews/TableContainer.js +25 -23
  21. package/dist/es2019/plugins/table/nodeviews/TableResizer.js +59 -29
  22. package/dist/es2019/plugins/table/nodeviews/table.js +5 -3
  23. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +4 -1
  24. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +2 -0
  25. package/dist/es2019/plugins/table/pm-plugins/main.js +2 -2
  26. package/dist/es2019/plugins/table/pm-plugins/table-resizing/plugin-factory.js +2 -0
  27. package/dist/es2019/plugins/table/ui/consts.js +3 -1
  28. package/dist/es2019/plugins/table/utils/collapse.js +2 -0
  29. package/dist/es2019/plugins/table/utils/decoration.js +2 -0
  30. package/dist/es2019/plugins/table/utils/guidelines.js +4 -0
  31. package/dist/es2019/plugins/table/utils/snapping.js +27 -0
  32. package/dist/es2019/version.json +1 -1
  33. package/dist/esm/plugins/table/handlers.js +1 -0
  34. package/dist/esm/plugins/table/index.js +1 -1
  35. package/dist/esm/plugins/table/nodeviews/TableComponent.js +4 -2
  36. package/dist/esm/plugins/table/nodeviews/TableContainer.js +50 -47
  37. package/dist/esm/plugins/table/nodeviews/TableResizer.js +61 -28
  38. package/dist/esm/plugins/table/nodeviews/table.js +5 -3
  39. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +4 -1
  40. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +2 -0
  41. package/dist/esm/plugins/table/pm-plugins/main.js +2 -2
  42. package/dist/esm/plugins/table/pm-plugins/table-resizing/plugin-factory.js +2 -0
  43. package/dist/esm/plugins/table/ui/consts.js +3 -1
  44. package/dist/esm/plugins/table/utils/collapse.js +2 -0
  45. package/dist/esm/plugins/table/utils/decoration.js +2 -0
  46. package/dist/esm/plugins/table/utils/guidelines.js +4 -0
  47. package/dist/esm/plugins/table/utils/snapping.js +30 -0
  48. package/dist/esm/version.json +1 -1
  49. package/dist/types/plugins/table/index.d.ts +3 -1
  50. package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -1
  51. package/dist/types/plugins/table/nodeviews/TableContainer.d.ts +5 -2
  52. package/dist/types/plugins/table/nodeviews/TableResizer.d.ts +3 -1
  53. package/dist/types/plugins/table/nodeviews/table.d.ts +2 -1
  54. package/dist/types/plugins/table/nodeviews/types.d.ts +2 -0
  55. package/dist/types/plugins/table/pm-plugins/main.d.ts +2 -1
  56. package/dist/types/plugins/table/types.d.ts +3 -0
  57. package/dist/types/plugins/table/ui/consts.d.ts +2 -0
  58. package/dist/types/plugins/table/utils/guidelines.d.ts +3 -0
  59. package/dist/types/plugins/table/utils/snapping.d.ts +8 -0
  60. package/dist/types-ts4.5/plugins/table/index.d.ts +3 -1
  61. package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -1
  62. package/dist/types-ts4.5/plugins/table/nodeviews/TableContainer.d.ts +5 -2
  63. package/dist/types-ts4.5/plugins/table/nodeviews/TableResizer.d.ts +3 -1
  64. package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +2 -1
  65. package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +2 -0
  66. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +2 -1
  67. package/dist/types-ts4.5/plugins/table/types.d.ts +3 -0
  68. package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +2 -0
  69. package/dist/types-ts4.5/plugins/table/utils/guidelines.d.ts +3 -0
  70. package/dist/types-ts4.5/plugins/table/utils/snapping.d.ts +8 -0
  71. package/package.json +3 -2
  72. package/report.api.md +2 -0
  73. package/src/__tests__/unit/analytics.ts +2 -0
  74. package/src/__tests__/unit/collab.ts +2 -0
  75. package/src/__tests__/unit/commands/go-to-next-cell.ts +2 -0
  76. package/src/__tests__/unit/commands/insert.ts +2 -0
  77. package/src/__tests__/unit/commands/misc.ts +2 -0
  78. package/src/__tests__/unit/commands/sort.ts +4 -0
  79. package/src/__tests__/unit/commands.ts +2 -0
  80. package/src/__tests__/unit/copy-paste.ts +2 -0
  81. package/src/__tests__/unit/event-handlers/index.ts +3 -0
  82. package/src/__tests__/unit/event-handlers.ts +3 -0
  83. package/src/__tests__/unit/fix-tables.ts +2 -0
  84. package/src/__tests__/unit/get-toolbar-config.ts +2 -0
  85. package/src/__tests__/unit/handlers.ts +2 -0
  86. package/src/__tests__/unit/hover-selection.ts +2 -0
  87. package/src/__tests__/unit/index.ts +2 -0
  88. package/src/__tests__/unit/layout.ts +2 -0
  89. package/src/__tests__/unit/nodeviews/cell.ts +2 -0
  90. package/src/__tests__/unit/nodeviews/table.ts +2 -0
  91. package/src/__tests__/unit/pm-plugins/decorations/column-resizing.ts +2 -0
  92. package/src/__tests__/unit/pm-plugins/decorations/plugin.ts +2 -0
  93. package/src/__tests__/unit/pm-plugins/main.ts +2 -0
  94. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +2 -0
  95. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +3 -0
  96. package/src/__tests__/unit/pm-plugins/table-resizing/event-handlers.ts +2 -0
  97. package/src/__tests__/unit/sort-column.ts +2 -0
  98. package/src/__tests__/unit/toolbar.ts +2 -0
  99. package/src/__tests__/unit/transforms/delete-columns.ts +2 -0
  100. package/src/__tests__/unit/transforms/delete-rows.ts +2 -0
  101. package/src/__tests__/unit/transforms/merging.ts +2 -0
  102. package/src/__tests__/unit/ui/ContextualMenu.tsx +2 -0
  103. package/src/__tests__/unit/ui/CornerControls.tsx +2 -0
  104. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +2 -0
  105. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +2 -0
  106. package/src/__tests__/unit/ui/RowControls.tsx +2 -0
  107. package/src/__tests__/unit/ui/TableFloatingControls.tsx +2 -0
  108. package/src/__tests__/unit/undo-redo.ts +2 -0
  109. package/src/__tests__/unit/utils/collapse.ts +2 -0
  110. package/src/__tests__/unit/utils/nodes.ts +2 -0
  111. package/src/__tests__/unit/utils/row-controls.ts +2 -0
  112. package/src/__tests__/unit/utils.ts +2 -0
  113. package/src/plugins/table/handlers.ts +1 -0
  114. package/src/plugins/table/index.tsx +3 -1
  115. package/src/plugins/table/nodeviews/TableComponent.tsx +4 -0
  116. package/src/plugins/table/nodeviews/TableContainer.tsx +31 -22
  117. package/src/plugins/table/nodeviews/TableResizer.tsx +100 -34
  118. package/src/plugins/table/nodeviews/table.tsx +4 -0
  119. package/src/plugins/table/nodeviews/types.ts +2 -0
  120. package/src/plugins/table/pm-plugins/decorations/plugin.ts +1 -0
  121. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +1 -0
  122. package/src/plugins/table/pm-plugins/decorations/utils/types.ts +1 -0
  123. package/src/plugins/table/pm-plugins/main.ts +3 -0
  124. package/src/plugins/table/pm-plugins/table-resizing/plugin-factory.ts +1 -0
  125. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +1 -0
  126. package/src/plugins/table/types.ts +4 -0
  127. package/src/plugins/table/ui/consts.ts +3 -0
  128. package/src/plugins/table/utils/collapse.ts +1 -0
  129. package/src/plugins/table/utils/decoration.ts +1 -0
  130. package/src/plugins/table/utils/guidelines.ts +17 -0
  131. package/src/plugins/table/utils/snapping.ts +38 -0
  132. package/tmp/api-report-tmp.d.ts +3 -1
@@ -5,10 +5,7 @@ import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
5
  import { TableCssClassName as ClassName } from '../types';
6
6
  import { TableResizer } from './TableResizer';
7
7
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
8
- const getMarginLeft = ({
9
- lineLength,
10
- tableWidth
11
- }) => {
8
+ const getMarginLeft = (lineLength, tableWidth) => {
12
9
  let marginLeft;
13
10
  if (tableWidth !== 'inherit' && lineLength) {
14
11
  const containerWidth = tableWidth;
@@ -41,35 +38,40 @@ export const ResizableTableContainer = ({
41
38
  containerWidth,
42
39
  editorView,
43
40
  getPos,
44
- tableRef
41
+ tableRef,
42
+ pluginInjectionApi
45
43
  }) => {
46
44
  const containerRef = useRef(null);
47
45
  const innerContainerRef = useRef(null);
46
+ const marginLeftRef = useRef(0);
48
47
  const updateWidth = useCallback(width => {
49
48
  if (!containerRef.current || !innerContainerRef.current) {
50
49
  return;
51
50
  }
52
- const marginLeft = getMarginLeft({
53
- lineLength,
54
- tableWidth: width
55
- });
56
- if (marginLeft) {
57
- containerRef.current.style.marginLeft = `${marginLeft}px`;
51
+ const marginLeft = getMarginLeft(lineLength, width);
52
+ if (marginLeftRef.current !== marginLeft) {
53
+ marginLeftRef.current = marginLeft;
54
+ if (Number.isFinite(marginLeft)) {
55
+ containerRef.current.style.marginLeft = `${marginLeft}px`;
56
+ }
58
57
  }
59
58
  }, [lineLength]);
59
+ const displayGuideline = useCallback(guidelines => {
60
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4;
61
+ return (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : (_pluginInjectionApi$d3 = _pluginInjectionApi$d2.guideline) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : (_pluginInjectionApi$d4 = _pluginInjectionApi$d3.actions) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.displayGuideline(editorView)({
62
+ guidelines
63
+ })) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : false;
64
+ }, [pluginInjectionApi, editorView]);
60
65
  const tableWidth = getTableContainerWidth(node);
61
66
 
62
67
  // 76 is currently an accepted padding value considering the spacing for resizer handle
63
68
  const responsiveContainerWidth = containerWidth - 76;
64
69
  const width = Math.min(tableWidth, responsiveContainerWidth);
65
- const marginLeft = getMarginLeft({
66
- lineLength,
67
- tableWidth: width
68
- });
70
+ marginLeftRef.current = getMarginLeft(lineLength, width);
69
71
  const maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
70
72
  return /*#__PURE__*/React.createElement("div", {
71
73
  style: {
72
- marginLeft,
74
+ marginLeft: marginLeftRef.current,
73
75
  width
74
76
  },
75
77
  className: ClassName.TABLE_RESIZER_CONTAINER,
@@ -81,7 +83,8 @@ export const ResizableTableContainer = ({
81
83
  editorView: editorView,
82
84
  getPos: getPos,
83
85
  node: node,
84
- tableRef: tableRef
86
+ tableRef: tableRef,
87
+ displayGuideline: displayGuideline
85
88
  }, /*#__PURE__*/React.createElement(InnerContainer, {
86
89
  ref: innerContainerRef,
87
90
  className: className,
@@ -101,7 +104,8 @@ export const TableContainer = ({
101
104
  editorView,
102
105
  getPos,
103
106
  tableRef,
104
- isNested
107
+ isNested,
108
+ pluginInjectionApi
105
109
  }) => {
106
110
  if ((isFullWidthModeEnabled || isBreakoutEnabled) && getBooleanFF('platform.editor.custom-table-width') && !isNested) {
107
111
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
@@ -111,7 +115,8 @@ export const TableContainer = ({
111
115
  containerWidth: editorWidth,
112
116
  editorView: editorView,
113
117
  getPos: getPos,
114
- tableRef: tableRef
118
+ tableRef: tableRef,
119
+ pluginInjectionApi: pluginInjectionApi
115
120
  }, children);
116
121
  }
117
122
  const tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
@@ -120,10 +125,7 @@ export const TableContainer = ({
120
125
  className: className,
121
126
  style: {
122
127
  width: tableWidth,
123
- marginLeft: getMarginLeft({
124
- lineLength: lineLength,
125
- tableWidth
126
- })
128
+ marginLeft: getMarginLeft(lineLength, tableWidth)
127
129
  }
128
130
  }, children);
129
131
  };
@@ -1,7 +1,11 @@
1
- import React from 'react';
1
+ import React, { useCallback, useRef, useMemo, useState } from 'react';
2
2
  import rafSchd from 'raf-schd';
3
3
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
4
+ import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
4
5
  import { scaleTable, previewScaleTable, getColgroupChildrenLength, COLUMN_MIN_WIDTH } from '../pm-plugins/table-resizing/utils';
6
+ import { defaultGuidelines, defaultGuidelineWidths } from '../utils/guidelines';
7
+ import { findClosestSnap } from '../utils/snapping';
8
+ import { TABLE_SNAP_GAP, TABLE_HIGHLIGHT_GAP } from '../ui/consts';
5
9
  const handles = {
6
10
  right: true
7
11
  };
@@ -14,7 +18,8 @@ export const TableResizer = ({
14
18
  editorView,
15
19
  getPos,
16
20
  node,
17
- tableRef
21
+ tableRef,
22
+ displayGuideline
18
23
  }) => {
19
24
  const currentColumnCount = getColgroupChildrenLength(node);
20
25
  const minColumnWidth = currentColumnCount <= 3 ? currentColumnCount * COLUMN_MIN_WIDTH : 3 * COLUMN_MIN_WIDTH;
@@ -33,13 +38,59 @@ export const TableResizer = ({
33
38
  } else if (tableHeight && tableHeight >= 96) {
34
39
  handleHeightSize = 'large';
35
40
  }
41
+ const currentGap = useRef(0);
42
+ const [snappingEnabled, setSnappingEnabled] = useState(false);
43
+ const updateActiveGuidelines = useCallback(({
44
+ gap,
45
+ keys
46
+ }) => {
47
+ if (gap !== currentGap.current) {
48
+ currentGap.current = gap;
49
+ displayGuideline(getGuidelinesWithHighlights(gap, TABLE_SNAP_GAP, keys, defaultGuidelines));
50
+ }
51
+ }, [displayGuideline]);
52
+ const guidelineSnaps = useMemo(() => snappingEnabled ? {
53
+ x: defaultGuidelineWidths
54
+ } : undefined, [snappingEnabled]);
55
+ const handleResizeStart = useCallback(() => {
56
+ setSnappingEnabled(displayGuideline(defaultGuidelines));
57
+ return width;
58
+ }, [width, displayGuideline]);
59
+ const handleResizeStop = useCallback((originalState, delta) => {
60
+ const newWidth = originalState.width + delta.width;
61
+ const {
62
+ state,
63
+ dispatch
64
+ } = editorView;
65
+ const pos = getPos();
66
+ if (typeof pos !== 'number') {
67
+ return;
68
+ }
69
+ let tr = state.tr.setNodeMarkup(pos, undefined, {
70
+ ...node.attrs,
71
+ width: newWidth
72
+ });
73
+ const newNode = tr.doc.nodeAt(pos);
74
+ tr = scaleTable(tableRef, {
75
+ node: newNode,
76
+ prevNode: node,
77
+ start: pos + 1,
78
+ parentWidth: newWidth
79
+ }, editorView.domAtPos.bind(editorView))(tr);
80
+ dispatch(tr);
81
+
82
+ // Hide guidelines when resizing stops
83
+ displayGuideline([]);
84
+ updateWidth(newWidth);
85
+ return newWidth;
86
+ }, [updateWidth, editorView, getPos, node, tableRef, displayGuideline]);
36
87
  return /*#__PURE__*/React.createElement(ResizerNext, {
37
88
  enable: handles,
38
89
  width: width,
39
90
  handleAlignmentMethod: "sticky",
40
91
  handleHeightSize: handleHeightSize,
41
92
  handleMarginTop: tableHandleMarginTop,
42
- handleResizeStart: () => width,
93
+ handleResizeStart: handleResizeStart,
43
94
  handleResize: rafSchd((originalState, delta) => {
44
95
  const newWidth = originalState.width + delta.width;
45
96
  const pos = getPos();
@@ -52,36 +103,15 @@ export const TableResizer = ({
52
103
  start: pos + 1,
53
104
  parentWidth: newWidth
54
105
  }, editorView.domAtPos.bind(editorView));
106
+ updateActiveGuidelines(findClosestSnap(newWidth, defaultGuidelineWidths, defaultGuidelines, TABLE_HIGHLIGHT_GAP));
55
107
  updateWidth(newWidth);
56
108
  return newWidth;
57
109
  }),
58
- handleResizeStop: (originalState, delta) => {
59
- const newWidth = originalState.width + delta.width;
60
- const {
61
- state,
62
- dispatch
63
- } = editorView;
64
- const pos = getPos();
65
- if (typeof pos !== 'number') {
66
- return;
67
- }
68
- let tr = state.tr.setNodeMarkup(pos, undefined, {
69
- ...node.attrs,
70
- width: newWidth
71
- });
72
- const newNode = tr.doc.nodeAt(pos);
73
- tr = scaleTable(tableRef, {
74
- node: newNode,
75
- prevNode: node,
76
- start: pos + 1,
77
- parentWidth: newWidth
78
- }, editorView.domAtPos.bind(editorView))(tr);
79
- dispatch(tr);
80
- updateWidth(newWidth);
81
- return newWidth;
82
- },
110
+ handleResizeStop: handleResizeStop,
83
111
  resizeRatio: 2,
84
112
  minWidth: minColumnWidth,
85
- maxWidth: maxWidth
113
+ maxWidth: maxWidth,
114
+ snapGap: TABLE_SNAP_GAP,
115
+ snap: guidelineSnaps
86
116
  }, children);
87
117
  };
@@ -112,7 +112,8 @@ export default class TableView extends ReactNodeView {
112
112
  getNode: this.getNode,
113
113
  containerWidth: containerWidth,
114
114
  contentDOM: forwardRef,
115
- getEditorFeatureFlags: props.getEditorFeatureFlags
115
+ getEditorFeatureFlags: props.getEditorFeatureFlags,
116
+ pluginInjectionApi: props.pluginInjectionApi
116
117
  });
117
118
  }
118
119
  });
@@ -176,7 +177,7 @@ export default class TableView extends ReactNodeView {
176
177
  super.destroy();
177
178
  }
178
179
  }
179
- export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, options, getEditorContainerWidth, getEditorFeatureFlags) => {
180
+ export const createTableView = (node, view, getPos, portalProviderAPI, eventDispatcher, options, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi) => {
180
181
  const {
181
182
  pluginConfig
182
183
  } = getPluginState(view.state);
@@ -198,6 +199,7 @@ export const createTableView = (node, view, getPos, portalProviderAPI, eventDisp
198
199
  tableRenderOptimization,
199
200
  getEditorContainerWidth,
200
201
  getEditorFeatureFlags,
201
- hasIntlContext
202
+ hasIntlContext,
203
+ pluginInjectionApi
202
204
  }).init();
203
205
  };
@@ -1,5 +1,8 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from 'prosemirror-state';
2
+ import { PluginKey
3
+
4
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
5
+ } from 'prosemirror-state';
3
6
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
7
  import { DecorationSet } from 'prosemirror-view';
5
8
  import { pluginKey as tablePluginKey } from '../plugin-key';
@@ -1,3 +1,5 @@
1
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
+
1
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
2
4
  import { findTable } from '@atlaskit/editor-tables/utils';
3
5
  import { TableDecorations } from '../../../types';
@@ -24,7 +24,7 @@ import { isHeaderRowRequired } from '../utils/paste';
24
24
  let isBreakoutEnabled;
25
25
  let isFullWidthModeEnabled;
26
26
  let wasFullWidthModeEnabled;
27
- export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, breakoutEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI) => {
27
+ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, breakoutEnabled, fullWidthModeEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI, pluginInjectionApi) => {
28
28
  var _window;
29
29
  isBreakoutEnabled = breakoutEnabled;
30
30
  isFullWidthModeEnabled = fullWidthModeEnabled;
@@ -232,7 +232,7 @@ export const createPlugin = (dispatchAnalyticsEvent, dispatch, portalProviderAPI
232
232
  isBreakoutEnabled,
233
233
  isFullWidthModeEnabled,
234
234
  wasFullWidthModeEnabled
235
- }, getEditorContainerWidth, getEditorFeatureFlags)
235
+ }, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi)
236
236
  },
237
237
  handleDOMEvents: {
238
238
  focus: handleFocus,
@@ -1,3 +1,5 @@
1
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
+
1
3
  import { pluginFactory } from '@atlaskit/editor-common/utils';
2
4
  import { pluginKey } from './plugin-key';
3
5
  import reducer from './reducer';
@@ -62,4 +62,6 @@ export const contextualMenuTriggerSize = 16;
62
62
  export const contextualMenuDropdownWidth = 180;
63
63
  export const stickyRowZIndex = resizeHandlerZIndex + 2;
64
64
  export const stickyRowOffsetTop = 8;
65
- export const stickyHeaderBorderBottomWidth = 1;
65
+ export const stickyHeaderBorderBottomWidth = 1;
66
+ export const TABLE_SNAP_GAP = 5;
67
+ export const TABLE_HIGHLIGHT_GAP = 10;
@@ -1,4 +1,6 @@
1
1
  import { NodeRange } from 'prosemirror-model';
2
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
3
+
2
4
  import { findWrapping } from 'prosemirror-transform';
3
5
  import { findTable } from '@atlaskit/editor-tables/utils';
4
6
  const bail = () => ({
@@ -1,3 +1,5 @@
1
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
2
+
1
3
  import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
2
4
  import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
3
5
  import { Decoration } from 'prosemirror-view';
@@ -0,0 +1,4 @@
1
+ import { createFixedGuidelinesFromLengths } from '@atlaskit/editor-common/guideline';
2
+ import { akEditorDefaultLayoutWidth, akEditorWideLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
3
+ export const defaultGuidelineWidths = [akEditorDefaultLayoutWidth, akEditorWideLayoutWidth, akEditorFullWidthLayoutWidth];
4
+ export const defaultGuidelines = createFixedGuidelinesFromLengths(defaultGuidelineWidths);
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns keys of guidelines that are closest to the table and withthin the snapGap
3
+ */
4
+ export const findClosestSnap = (currentWidth, snapWidths, guidelines, snapGap = 0) => {
5
+ const closestGapIndex = snapWidths.reduce((prev, curr, index) => Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev, 0);
6
+ const gap = Math.abs(snapWidths[closestGapIndex] - currentWidth);
7
+ if (gap < snapGap) {
8
+ const snappingWidth = Math.round(snapWidths[closestGapIndex]);
9
+ const guidelineKeys = guidelines.reduce((acc, guideline) => {
10
+ // NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
11
+ // are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
12
+ // point base position to length by simply multiplying by 2.
13
+ if (Math.round(Math.abs(guideline.position.x) * 2) === snappingWidth) {
14
+ acc.push(guideline.key);
15
+ }
16
+ return acc;
17
+ }, []);
18
+ return {
19
+ gap,
20
+ keys: guidelineKeys
21
+ };
22
+ }
23
+ return {
24
+ gap,
25
+ keys: []
26
+ };
27
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.1.7",
3
+ "version": "2.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -2,6 +2,7 @@ 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
4
  // #region Imports
5
+ // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
5
6
 
6
7
  import { findParentNodeOfType } from 'prosemirror-utils';
7
8
  import { findTable } from '@atlaskit/editor-tables/utils';
@@ -96,7 +96,7 @@ var tablesPlugin = function tablesPlugin(options, api) {
96
96
  breakoutEnabled = _ref2.breakoutEnabled,
97
97
  tableOptions = _ref2.tableOptions,
98
98
  getEditorFeatureFlags = _ref2.getEditorFeatureFlags;
99
- return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI);
99
+ return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI, api);
100
100
  }
101
101
  }, {
102
102
  name: 'tablePMColResizing',
@@ -387,7 +387,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
387
387
  tableActive = _this$props8.tableActive,
388
388
  containerWidth = _this$props8.containerWidth,
389
389
  options = _this$props8.options,
390
- getPos = _this$props8.getPos;
390
+ getPos = _this$props8.getPos,
391
+ pluginInjectionApi = _this$props8.pluginInjectionApi;
391
392
  var _this$state = this.state,
392
393
  isLoading = _this$state.isLoading,
393
394
  showBeforeShadow = _this$state.showBeforeShadow,
@@ -447,7 +448,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
447
448
  containerWidth: containerWidth,
448
449
  isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.isFullWidthModeEnabled,
449
450
  isBreakoutEnabled: options === null || options === void 0 ? void 0 : options.isBreakoutEnabled,
450
- isNested: isNested
451
+ isNested: isNested,
452
+ pluginInjectionApi: pluginInjectionApi
451
453
  }, stickyHeadersOptimization && /*#__PURE__*/React.createElement("div", {
452
454
  className: ClassName.TABLE_STICKY_SENTINEL_TOP,
453
455
  "data-testid": "sticky-sentinel-top"
@@ -5,9 +5,7 @@ import { calcTableWidth } from '@atlaskit/editor-common/styles';
5
5
  import { TableCssClassName as ClassName } from '../types';
6
6
  import { TableResizer } from './TableResizer';
7
7
  import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
8
- var getMarginLeft = function getMarginLeft(_ref) {
9
- var lineLength = _ref.lineLength,
10
- tableWidth = _ref.tableWidth;
8
+ var getMarginLeft = function getMarginLeft(lineLength, tableWidth) {
11
9
  var marginLeft;
12
10
  if (tableWidth !== 'inherit' && lineLength) {
13
11
  var containerWidth = tableWidth;
@@ -17,11 +15,11 @@ var getMarginLeft = function getMarginLeft(_ref) {
17
15
  }
18
16
  return marginLeft;
19
17
  };
20
- export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
21
- var className = _ref2.className,
22
- style = _ref2.style,
23
- node = _ref2.node,
24
- children = _ref2.children;
18
+ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
19
+ var className = _ref.className,
20
+ style = _ref.style,
21
+ node = _ref.node,
22
+ children = _ref.children;
25
23
  return /*#__PURE__*/React.createElement("div", {
26
24
  ref: ref,
27
25
  style: style,
@@ -31,42 +29,47 @@ export var InnerContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
31
29
  "data-test-id": "table-container"
32
30
  }, children);
33
31
  });
34
- export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
35
- var children = _ref3.children,
36
- className = _ref3.className,
37
- node = _ref3.node,
38
- lineLength = _ref3.lineLength,
39
- containerWidth = _ref3.containerWidth,
40
- editorView = _ref3.editorView,
41
- getPos = _ref3.getPos,
42
- tableRef = _ref3.tableRef;
32
+ export var ResizableTableContainer = function ResizableTableContainer(_ref2) {
33
+ var children = _ref2.children,
34
+ className = _ref2.className,
35
+ node = _ref2.node,
36
+ lineLength = _ref2.lineLength,
37
+ containerWidth = _ref2.containerWidth,
38
+ editorView = _ref2.editorView,
39
+ getPos = _ref2.getPos,
40
+ tableRef = _ref2.tableRef,
41
+ pluginInjectionApi = _ref2.pluginInjectionApi;
43
42
  var containerRef = useRef(null);
44
43
  var innerContainerRef = useRef(null);
44
+ var marginLeftRef = useRef(0);
45
45
  var updateWidth = useCallback(function (width) {
46
46
  if (!containerRef.current || !innerContainerRef.current) {
47
47
  return;
48
48
  }
49
- var marginLeft = getMarginLeft({
50
- lineLength: lineLength,
51
- tableWidth: width
52
- });
53
- if (marginLeft) {
54
- containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
49
+ var marginLeft = getMarginLeft(lineLength, width);
50
+ if (marginLeftRef.current !== marginLeft) {
51
+ marginLeftRef.current = marginLeft;
52
+ if (Number.isFinite(marginLeft)) {
53
+ containerRef.current.style.marginLeft = "".concat(marginLeft, "px");
54
+ }
55
55
  }
56
56
  }, [lineLength]);
57
+ var displayGuideline = useCallback(function (guidelines) {
58
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4;
59
+ return (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : (_pluginInjectionApi$d3 = _pluginInjectionApi$d2.guideline) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : (_pluginInjectionApi$d4 = _pluginInjectionApi$d3.actions) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.displayGuideline(editorView)({
60
+ guidelines: guidelines
61
+ })) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : false;
62
+ }, [pluginInjectionApi, editorView]);
57
63
  var tableWidth = getTableContainerWidth(node);
58
64
 
59
65
  // 76 is currently an accepted padding value considering the spacing for resizer handle
60
66
  var responsiveContainerWidth = containerWidth - 76;
61
67
  var width = Math.min(tableWidth, responsiveContainerWidth);
62
- var marginLeft = getMarginLeft({
63
- lineLength: lineLength,
64
- tableWidth: width
65
- });
68
+ marginLeftRef.current = getMarginLeft(lineLength, width);
66
69
  var maxResizerWidth = Math.min(responsiveContainerWidth, TABLE_MAX_WIDTH);
67
70
  return /*#__PURE__*/React.createElement("div", {
68
71
  style: {
69
- marginLeft: marginLeft,
72
+ marginLeft: marginLeftRef.current,
70
73
  width: width
71
74
  },
72
75
  className: ClassName.TABLE_RESIZER_CONTAINER,
@@ -78,26 +81,28 @@ export var ResizableTableContainer = function ResizableTableContainer(_ref3) {
78
81
  editorView: editorView,
79
82
  getPos: getPos,
80
83
  node: node,
81
- tableRef: tableRef
84
+ tableRef: tableRef,
85
+ displayGuideline: displayGuideline
82
86
  }, /*#__PURE__*/React.createElement(InnerContainer, {
83
87
  ref: innerContainerRef,
84
88
  className: className,
85
89
  node: node
86
90
  }, children)));
87
91
  };
88
- export var TableContainer = function TableContainer(_ref4) {
89
- var children = _ref4.children,
90
- node = _ref4.node,
91
- className = _ref4.className,
92
- _ref4$containerWidth = _ref4.containerWidth,
93
- lineLength = _ref4$containerWidth.lineLength,
94
- editorWidth = _ref4$containerWidth.width,
95
- isFullWidthModeEnabled = _ref4.isFullWidthModeEnabled,
96
- isBreakoutEnabled = _ref4.isBreakoutEnabled,
97
- editorView = _ref4.editorView,
98
- getPos = _ref4.getPos,
99
- tableRef = _ref4.tableRef,
100
- isNested = _ref4.isNested;
92
+ export var TableContainer = function TableContainer(_ref3) {
93
+ var children = _ref3.children,
94
+ node = _ref3.node,
95
+ className = _ref3.className,
96
+ _ref3$containerWidth = _ref3.containerWidth,
97
+ lineLength = _ref3$containerWidth.lineLength,
98
+ editorWidth = _ref3$containerWidth.width,
99
+ isFullWidthModeEnabled = _ref3.isFullWidthModeEnabled,
100
+ isBreakoutEnabled = _ref3.isBreakoutEnabled,
101
+ editorView = _ref3.editorView,
102
+ getPos = _ref3.getPos,
103
+ tableRef = _ref3.tableRef,
104
+ isNested = _ref3.isNested,
105
+ pluginInjectionApi = _ref3.pluginInjectionApi;
101
106
  if ((isFullWidthModeEnabled || isBreakoutEnabled) && getBooleanFF('platform.editor.custom-table-width') && !isNested) {
102
107
  return /*#__PURE__*/React.createElement(ResizableTableContainer, {
103
108
  className: className,
@@ -106,7 +111,8 @@ export var TableContainer = function TableContainer(_ref4) {
106
111
  containerWidth: editorWidth,
107
112
  editorView: editorView,
108
113
  getPos: getPos,
109
- tableRef: tableRef
114
+ tableRef: tableRef,
115
+ pluginInjectionApi: pluginInjectionApi
110
116
  }, children);
111
117
  }
112
118
  var tableWidth = isBreakoutEnabled ? calcTableWidth(node.attrs.layout, editorWidth) : 'inherit';
@@ -115,10 +121,7 @@ export var TableContainer = function TableContainer(_ref4) {
115
121
  className: className,
116
122
  style: {
117
123
  width: tableWidth,
118
- marginLeft: getMarginLeft({
119
- lineLength: lineLength,
120
- tableWidth: tableWidth
121
- })
124
+ marginLeft: getMarginLeft(lineLength, tableWidth)
122
125
  }
123
126
  }, children);
124
127
  };