@atlaskit/editor-plugin-table 5.1.0 → 5.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 (77) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/index.js +3 -2
  3. package/dist/cjs/plugins/table/nodeviews/TableCell.js +111 -0
  4. package/dist/cjs/plugins/table/nodeviews/TableNodeViewBase.js +30 -0
  5. package/dist/cjs/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +313 -307
  6. package/dist/cjs/plugins/table/pm-plugins/main.js +16 -13
  7. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/index.js +1 -8
  8. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
  9. package/dist/cjs/plugins/table/utils/dom.js +31 -1
  10. package/dist/cjs/plugins/table/utils/index.js +12 -0
  11. package/dist/cjs/plugins/table/utils/nodes.js +31 -7
  12. package/dist/es2019/plugins/table/index.js +3 -2
  13. package/dist/es2019/plugins/table/nodeviews/{tableCell.js → TableCell.js} +28 -24
  14. package/dist/es2019/plugins/table/nodeviews/TableNodeViewBase.js +22 -0
  15. package/dist/es2019/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +273 -284
  16. package/dist/es2019/plugins/table/pm-plugins/main.js +8 -8
  17. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
  18. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
  19. package/dist/es2019/plugins/table/utils/dom.js +30 -0
  20. package/dist/es2019/plugins/table/utils/index.js +1 -1
  21. package/dist/es2019/plugins/table/utils/nodes.js +16 -0
  22. package/dist/esm/plugins/table/index.js +3 -2
  23. package/dist/esm/plugins/table/nodeviews/TableCell.js +105 -0
  24. package/dist/esm/plugins/table/nodeviews/TableNodeViewBase.js +24 -0
  25. package/dist/esm/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +314 -307
  26. package/dist/esm/plugins/table/pm-plugins/main.js +16 -13
  27. package/dist/esm/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
  28. package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
  29. package/dist/esm/plugins/table/utils/dom.js +30 -0
  30. package/dist/esm/plugins/table/utils/index.js +1 -1
  31. package/dist/esm/plugins/table/utils/nodes.js +24 -0
  32. package/dist/types/plugins/table/nodeviews/TableCell.d.ts +13 -0
  33. package/dist/types/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
  34. package/dist/types/plugins/table/nodeviews/TableRow.d.ts +60 -0
  35. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  36. package/dist/types/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
  37. package/dist/types/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
  38. package/dist/types/plugins/table/types.d.ts +1 -0
  39. package/dist/types/plugins/table/utils/dom.d.ts +6 -0
  40. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  41. package/dist/types/plugins/table/utils/nodes.d.ts +12 -2
  42. package/dist/types-ts4.5/plugins/table/nodeviews/TableCell.d.ts +13 -0
  43. package/dist/types-ts4.5/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
  44. package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +60 -0
  45. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  46. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
  47. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
  48. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  49. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +6 -0
  50. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  51. package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +12 -2
  52. package/package.json +1 -1
  53. package/src/__tests__/unit/nodeviews/cell.ts +2 -2
  54. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +25 -148
  55. package/src/plugins/table/index.tsx +2 -0
  56. package/src/plugins/table/nodeviews/{tableCell.tsx → TableCell.ts} +41 -46
  57. package/src/plugins/table/nodeviews/TableNodeViewBase.ts +32 -0
  58. package/src/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.ts → nodeviews/TableRow.ts} +193 -246
  59. package/src/plugins/table/pm-plugins/main.ts +10 -19
  60. package/src/plugins/table/pm-plugins/sticky-headers/index.ts +0 -1
  61. package/src/plugins/table/pm-plugins/sticky-headers/plugin.ts +1 -9
  62. package/src/plugins/table/types.ts +2 -0
  63. package/src/plugins/table/utils/dom.ts +38 -0
  64. package/src/plugins/table/utils/index.ts +2 -0
  65. package/src/plugins/table/utils/nodes.ts +30 -2
  66. package/dist/cjs/plugins/table/nodeviews/tableCell.js +0 -99
  67. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -35
  68. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
  69. package/dist/esm/plugins/table/nodeviews/tableCell.js +0 -93
  70. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
  71. package/dist/types/plugins/table/nodeviews/tableCell.d.ts +0 -17
  72. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  73. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  74. package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
  75. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  76. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  77. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.ts +0 -37
@@ -13,7 +13,8 @@ import { addBoldInEmptyHeaderCells, clearHoverSelection, setTableRef } from '../
13
13
  import { removeResizeHandleDecorations, transformSliceRemoveCellBackgroundColor, transformSliceToAddTableHeaders, transformSliceToRemoveColumnsWidths } from '../commands/misc';
14
14
  import { handleBlur, handleClick, handleCut, handleFocus, handleMouseDown, handleMouseLeave, handleMouseMove, handleMouseOut, handleMouseOver, handleTripleClick, whenTableInFocus } from '../event-handlers';
15
15
  import { createTableView } from '../nodeviews/table';
16
- import TableCellNodeView from '../nodeviews/tableCell';
16
+ import TableCell from '../nodeviews/TableCell';
17
+ import TableRow from '../nodeviews/TableRow';
17
18
  import { pluginKey as decorationsPluginKey } from '../pm-plugins/decorations/plugin';
18
19
  import { fixTables, replaceSelectedTable } from '../transforms';
19
20
  import { TableCssClassName as ClassName } from '../types';
@@ -22,7 +23,7 @@ import { isHeaderRowRequired } from '../utils/paste';
22
23
  import { defaultTableSelection } from './default-table-selection';
23
24
  import { createPluginState, getPluginState } from './plugin-factory';
24
25
  import { pluginKey } from './plugin-key';
25
- export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, fullWidthModeEnabled, tableResizingEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI, pluginInjectionApi) {
26
+ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, breakoutEnabled, fullWidthModeEnabled, tableResizingEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi) {
26
27
  var _window;
27
28
  var state = createPluginState(dispatch, _objectSpread(_objectSpread({
28
29
  pluginConfig: pluginConfig,
@@ -33,7 +34,8 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
33
34
  wasFullWidthModeEnabled: previousFullWidthModeEnabled,
34
35
  isTableResizingEnabled: tableResizingEnabled,
35
36
  isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
36
- isHeaderColumnEnabled: false
37
+ isHeaderColumnEnabled: false,
38
+ isDragAndDropEnabled: dragAndDropEnabled
37
39
  }, defaultTableSelection), {}, {
38
40
  getIntl: getIntl
39
41
  }));
@@ -46,14 +48,6 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
46
48
  elementContentRects[entry.target.id] = entry.contentRect;
47
49
  });
48
50
  }) : undefined;
49
- var tableCellNodeview = {
50
- tableCell: function tableCell(node, view, getPos) {
51
- return new TableCellNodeView(node, view, getPos, observer);
52
- },
53
- tableHeader: function tableHeader(node, view, getPos) {
54
- return new TableCellNodeView(node, view, getPos, observer);
55
- }
56
- };
57
51
 
58
52
  // Used to prevent invalid table cell spans being reported more than once per editor/document
59
53
  var invalidTableIds = [];
@@ -229,11 +223,20 @@ export var createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch
229
223
  }
230
224
  return false;
231
225
  },
232
- nodeViews: _objectSpread(_objectSpread({}, tableCellNodeview), {}, {
226
+ nodeViews: {
233
227
  table: function table(node, view, getPos) {
234
228
  return createTableView(node, view, getPos, portalProviderAPI, eventDispatcher, getEditorContainerWidth, getEditorFeatureFlags, pluginInjectionApi);
229
+ },
230
+ tableRow: function tableRow(node, view, getPos) {
231
+ return new TableRow(node, view, getPos, eventDispatcher);
232
+ },
233
+ tableCell: function tableCell(node, view, getPos) {
234
+ return new TableCell(node, view, getPos, eventDispatcher, observer);
235
+ },
236
+ tableHeader: function tableHeader(node, view, getPos) {
237
+ return new TableCell(node, view, getPos, eventDispatcher, observer);
235
238
  }
236
- }),
239
+ },
237
240
  handleDOMEvents: {
238
241
  focus: handleFocus,
239
242
  blur: handleBlur,
@@ -1,5 +1,4 @@
1
1
  export { createPlugin } from './plugin';
2
2
  export { pluginKey } from './plugin-key';
3
3
  export { findStickyHeaderForTable } from './util';
4
- export { updateStickyState, removeStickyState } from './commands';
5
- export { TableRowNodeView } from './nodeviews/tableRow';
4
+ export { updateStickyState, removeStickyState } from './commands';
@@ -1,5 +1,4 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { TableRowNodeView } from './nodeviews/tableRow';
3
2
  import { pluginKey } from './plugin-key';
4
3
  import { createPluginState } from './plugin-state';
5
4
  export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
@@ -9,13 +8,6 @@ export var createPlugin = function createPlugin(dispatch, eventDispatcher) {
9
8
  var getEditorFeatureFlags = arguments.length > 3 ? arguments[3] : undefined;
10
9
  return new SafePlugin({
11
10
  state: createPluginState(dispatch, initialState),
12
- key: pluginKey,
13
- props: {
14
- nodeViews: {
15
- tableRow: function tableRow(node, view, getPos) {
16
- return new TableRowNodeView(node, view, getPos, eventDispatcher);
17
- }
18
- }
19
- }
11
+ key: pluginKey
20
12
  });
21
13
  };
@@ -150,4 +150,34 @@ export var hasResizeHandler = function hasResizeHandler(_ref) {
150
150
  return false;
151
151
  }
152
152
  return true;
153
+ };
154
+ export var getTree = function getTree(tr) {
155
+ // pm renders into tbody, owned by react
156
+ var tbody = tr.parentElement;
157
+ if (!tbody) {
158
+ return null;
159
+ }
160
+
161
+ // rendered by react
162
+ var table = tbody.parentElement;
163
+ if (!table) {
164
+ return null;
165
+ }
166
+
167
+ // rendered by react
168
+ var wrapper = table.parentElement;
169
+ if (!wrapper) {
170
+ return null;
171
+ }
172
+ return {
173
+ wrapper: wrapper,
174
+ table: table
175
+ };
176
+ };
177
+ export var getTop = function getTop(element) {
178
+ var _element$getBoundingC, _element$getBoundingC2;
179
+ if (!element || element instanceof Window) {
180
+ return 0;
181
+ }
182
+ return (_element$getBoundingC = element === null || element === void 0 || (_element$getBoundingC2 = element.getBoundingClientRect) === null || _element$getBoundingC2 === void 0 || (_element$getBoundingC2 = _element$getBoundingC2.call(element)) === null || _element$getBoundingC2 === void 0 ? void 0 : _element$getBoundingC2.top) !== null && _element$getBoundingC !== void 0 ? _element$getBoundingC : 0;
153
183
  };
@@ -1,6 +1,6 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated } from './selection';
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize } from './decoration';
3
- export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested } from './nodes';
3
+ export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler } from './dom';
6
6
  export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames } from './column-controls';
@@ -1,4 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { mapChildren } from '@atlaskit/editor-common/utils';
2
3
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
3
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
4
5
  import { findTable } from '@atlaskit/editor-tables/utils';
@@ -104,4 +105,27 @@ export var isTableNested = function isTableNested(state) {
104
105
  var parent = state.doc.resolve(tablePos).parent;
105
106
  var nodeTypes = state.schema.nodes;
106
107
  return parent.type === nodeTypes.layoutColumn || parent.type === nodeTypes.expand || parent.type === nodeTypes.bodiedExtension;
108
+ };
109
+ export var anyChildCellMergedAcrossRow = function anyChildCellMergedAcrossRow(node) {
110
+ return mapChildren(node, function (child) {
111
+ return child.attrs.rowspan || 0;
112
+ }).some(function (rowspan) {
113
+ return rowspan > 1;
114
+ });
115
+ };
116
+
117
+ /**
118
+ * Check if a given node is a header row with this definition:
119
+ * - all children are tableHeader cells
120
+ * - no table cells have been have merged with other table row cells
121
+ *
122
+ * @param node ProseMirror node
123
+ * @return boolean if it meets definition
124
+ */
125
+ export var supportedHeaderRow = function supportedHeaderRow(node) {
126
+ var allHeaders = mapChildren(node, function (child) {
127
+ return child.type.name === 'tableHeader';
128
+ }).every(Boolean);
129
+ var someMerged = anyChildCellMergedAcrossRow(node);
130
+ return allHeaders && !someMerged;
107
131
  };
@@ -0,0 +1,13 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ import TableNodeView from './TableNodeViewBase';
5
+ export default class TableCell extends TableNodeView<HTMLElement> implements NodeView {
6
+ private readonly observer?;
7
+ constructor(node: PMNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher, observer?: ResizeObserver | undefined);
8
+ private isStickyHeaderEnabled;
9
+ private isDragAndDropEnabled;
10
+ update(node: PMNode): boolean;
11
+ destroy(): void;
12
+ private updateNodeView;
13
+ }
@@ -0,0 +1,18 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ export default abstract class TableNodeView<T extends HTMLElement> implements NodeView {
5
+ protected node: PmNode;
6
+ protected readonly view: EditorView;
7
+ protected readonly getPos: () => number | undefined;
8
+ protected readonly eventDispatcher: EventDispatcher;
9
+ /**
10
+ * @constructor
11
+ */
12
+ constructor(node: PmNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher);
13
+ /**
14
+ * Variables
15
+ */
16
+ dom: T;
17
+ contentDOM: T;
18
+ }
@@ -0,0 +1,60 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ import TableNodeView from './TableNodeViewBase';
5
+ export default class TableRow extends TableNodeView<HTMLTableRowElement> implements NodeView {
6
+ constructor(node: PMNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher);
7
+ /**
8
+ * Variables
9
+ */
10
+ private isHeaderRow;
11
+ private isStickyHeaderEnabled;
12
+ private isDragAndDropEnabled;
13
+ private editorScrollableElement?;
14
+ private colControlsOffset;
15
+ private focused;
16
+ private topPosEditorElement;
17
+ private isSticky;
18
+ private lastStickyTimestamp;
19
+ private intersectionObserver?;
20
+ private resizeObserver?;
21
+ private sentinels;
22
+ private stickyRowHeight?;
23
+ private listening;
24
+ private padding;
25
+ private top;
26
+ /**
27
+ * Methods: Nodeview Lifecycle
28
+ */
29
+ update(node: PMNode, ..._args: any[]): boolean;
30
+ destroy(): void;
31
+ ignoreMutation(mutationRecord: MutationRecord | {
32
+ type: 'selection';
33
+ target: Element;
34
+ }): boolean;
35
+ /**
36
+ * Methods
37
+ */
38
+ private headerRowMouseScrollEnd;
39
+ private headerRowMouseScroll;
40
+ private subscribe;
41
+ private unsubscribe;
42
+ private initObservers;
43
+ private createResizeObserver;
44
+ private createIntersectionObserver;
45
+ private onTablePluginState;
46
+ private updateStickyHeaderWidth;
47
+ /**
48
+ * Manually refire the intersection observers.
49
+ * Useful when the header may have detached from the table.
50
+ */
51
+ private refireIntersectionObservers;
52
+ private makeHeaderRowSticky;
53
+ private makeRowHeaderNotSticky;
54
+ private getWrapperoffset;
55
+ private getWrapperRefTop;
56
+ private getScrolledTableTop;
57
+ private getCurrentTableTop;
58
+ private emitOn;
59
+ private emitOff;
60
+ }
@@ -5,4 +5,4 @@ import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider'
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
7
  import type { PluginConfig, PluginInjectionAPI } from '../types';
8
- export declare const createPlugin: (dispatchAnalyticsEvent: DispatchAnalyticsEvent, dispatch: Dispatch, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, pluginConfig: PluginConfig, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, getIntl: () => IntlShape, breakoutEnabled?: boolean, fullWidthModeEnabled?: boolean, tableResizingEnabled?: boolean, previousFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, pluginInjectionApi?: PluginInjectionAPI) => SafePlugin<import("../types").TablePluginState>;
8
+ export declare const createPlugin: (dispatchAnalyticsEvent: DispatchAnalyticsEvent, dispatch: Dispatch, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, pluginConfig: PluginConfig, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, getIntl: () => IntlShape, breakoutEnabled?: boolean, fullWidthModeEnabled?: boolean, tableResizingEnabled?: boolean, previousFullWidthModeEnabled?: boolean, dragAndDropEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, pluginInjectionApi?: PluginInjectionAPI) => SafePlugin<import("../types").TablePluginState>;
@@ -3,4 +3,3 @@ export { pluginKey } from './plugin-key';
3
3
  export type { StickyPluginState, RowStickyState } from './types';
4
4
  export { findStickyHeaderForTable } from './util';
5
5
  export { updateStickyState, removeStickyState } from './commands';
6
- export { TableRowNodeView } from './nodeviews/tableRow';
@@ -1,4 +1,4 @@
1
- import { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
1
+ import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
4
  export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher, initialState: (() => never[]) | undefined, getEditorFeatureFlags: GetEditorFeatureFlags) => SafePlugin<import("./types").StickyPluginState>;
@@ -73,6 +73,7 @@ export interface TablePluginState {
73
73
  isBreakoutEnabled?: boolean;
74
74
  wasFullWidthModeEnabled?: boolean;
75
75
  isTableResizingEnabled?: boolean;
76
+ isDragAndDropEnabled?: boolean;
76
77
  }
77
78
  export type TablePluginAction = {
78
79
  type: 'SET_EDITOR_FOCUS';
@@ -15,3 +15,9 @@ export declare const hasResizeHandler: ({ columnEndIndexTarget, target, }: {
15
15
  columnEndIndexTarget: number;
16
16
  target: HTMLElement;
17
17
  }) => boolean;
18
+ export type TableDOMElements = {
19
+ wrapper: HTMLDivElement;
20
+ table: HTMLTableElement;
21
+ };
22
+ export declare const getTree: (tr: HTMLTableRowElement) => TableDOMElements | null;
23
+ export declare const getTop: (element: HTMLElement | Window | undefined) => number;
@@ -1,6 +1,6 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated, } from './selection';
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize, } from './decoration';
3
- export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, } from './nodes';
3
+ export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow, } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, } from './dom';
6
6
  export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames, } from './column-controls';
@@ -1,5 +1,5 @@
1
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const isIsolating: (node: PmNode) => boolean;
4
4
  export declare const containsHeaderColumn: (table: PmNode) => boolean;
5
5
  export declare const containsHeaderRow: (table: PmNode) => boolean;
@@ -11,3 +11,13 @@ export declare const getTableWidth: (node: PmNode) => number;
11
11
  export declare const tablesHaveDifferentColumnWidths: (currentTable: PmNode, previousTable: PmNode) => boolean;
12
12
  export declare const tablesHaveDifferentNoOfColumns: (currentTable: PmNode, previousTable: PmNode) => boolean;
13
13
  export declare const isTableNested: (state: EditorState, tablePos?: number) => boolean;
14
+ export declare const anyChildCellMergedAcrossRow: (node: PmNode) => boolean;
15
+ /**
16
+ * Check if a given node is a header row with this definition:
17
+ * - all children are tableHeader cells
18
+ * - no table cells have been have merged with other table row cells
19
+ *
20
+ * @param node ProseMirror node
21
+ * @return boolean if it meets definition
22
+ */
23
+ export declare const supportedHeaderRow: (node: PmNode) => boolean;
@@ -0,0 +1,13 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ import TableNodeView from './TableNodeViewBase';
5
+ export default class TableCell extends TableNodeView<HTMLElement> implements NodeView {
6
+ private readonly observer?;
7
+ constructor(node: PMNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher, observer?: ResizeObserver | undefined);
8
+ private isStickyHeaderEnabled;
9
+ private isDragAndDropEnabled;
10
+ update(node: PMNode): boolean;
11
+ destroy(): void;
12
+ private updateNodeView;
13
+ }
@@ -0,0 +1,18 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ export default abstract class TableNodeView<T extends HTMLElement> implements NodeView {
5
+ protected node: PmNode;
6
+ protected readonly view: EditorView;
7
+ protected readonly getPos: () => number | undefined;
8
+ protected readonly eventDispatcher: EventDispatcher;
9
+ /**
10
+ * @constructor
11
+ */
12
+ constructor(node: PmNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher);
13
+ /**
14
+ * Variables
15
+ */
16
+ dom: T;
17
+ contentDOM: T;
18
+ }
@@ -0,0 +1,60 @@
1
+ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
4
+ import TableNodeView from './TableNodeViewBase';
5
+ export default class TableRow extends TableNodeView<HTMLTableRowElement> implements NodeView {
6
+ constructor(node: PMNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher);
7
+ /**
8
+ * Variables
9
+ */
10
+ private isHeaderRow;
11
+ private isStickyHeaderEnabled;
12
+ private isDragAndDropEnabled;
13
+ private editorScrollableElement?;
14
+ private colControlsOffset;
15
+ private focused;
16
+ private topPosEditorElement;
17
+ private isSticky;
18
+ private lastStickyTimestamp;
19
+ private intersectionObserver?;
20
+ private resizeObserver?;
21
+ private sentinels;
22
+ private stickyRowHeight?;
23
+ private listening;
24
+ private padding;
25
+ private top;
26
+ /**
27
+ * Methods: Nodeview Lifecycle
28
+ */
29
+ update(node: PMNode, ..._args: any[]): boolean;
30
+ destroy(): void;
31
+ ignoreMutation(mutationRecord: MutationRecord | {
32
+ type: 'selection';
33
+ target: Element;
34
+ }): boolean;
35
+ /**
36
+ * Methods
37
+ */
38
+ private headerRowMouseScrollEnd;
39
+ private headerRowMouseScroll;
40
+ private subscribe;
41
+ private unsubscribe;
42
+ private initObservers;
43
+ private createResizeObserver;
44
+ private createIntersectionObserver;
45
+ private onTablePluginState;
46
+ private updateStickyHeaderWidth;
47
+ /**
48
+ * Manually refire the intersection observers.
49
+ * Useful when the header may have detached from the table.
50
+ */
51
+ private refireIntersectionObservers;
52
+ private makeHeaderRowSticky;
53
+ private makeRowHeaderNotSticky;
54
+ private getWrapperoffset;
55
+ private getWrapperRefTop;
56
+ private getScrolledTableTop;
57
+ private getCurrentTableTop;
58
+ private emitOn;
59
+ private emitOff;
60
+ }
@@ -5,4 +5,4 @@ import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider'
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
7
  import type { PluginConfig, PluginInjectionAPI } from '../types';
8
- export declare const createPlugin: (dispatchAnalyticsEvent: DispatchAnalyticsEvent, dispatch: Dispatch, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, pluginConfig: PluginConfig, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, getIntl: () => IntlShape, breakoutEnabled?: boolean, fullWidthModeEnabled?: boolean, tableResizingEnabled?: boolean, previousFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, pluginInjectionApi?: PluginInjectionAPI) => SafePlugin<import("../types").TablePluginState>;
8
+ export declare const createPlugin: (dispatchAnalyticsEvent: DispatchAnalyticsEvent, dispatch: Dispatch, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, pluginConfig: PluginConfig, getEditorContainerWidth: GetEditorContainerWidth, getEditorFeatureFlags: GetEditorFeatureFlags, getIntl: () => IntlShape, breakoutEnabled?: boolean, fullWidthModeEnabled?: boolean, tableResizingEnabled?: boolean, previousFullWidthModeEnabled?: boolean, dragAndDropEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI, pluginInjectionApi?: PluginInjectionAPI) => SafePlugin<import("../types").TablePluginState>;
@@ -3,4 +3,3 @@ export { pluginKey } from './plugin-key';
3
3
  export type { StickyPluginState, RowStickyState } from './types';
4
4
  export { findStickyHeaderForTable } from './util';
5
5
  export { updateStickyState, removeStickyState } from './commands';
6
- export { TableRowNodeView } from './nodeviews/tableRow';
@@ -1,4 +1,4 @@
1
- import { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
1
+ import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
4
4
  export declare const createPlugin: (dispatch: Dispatch, eventDispatcher: EventDispatcher, initialState: (() => never[]) | undefined, getEditorFeatureFlags: GetEditorFeatureFlags) => SafePlugin<import("./types").StickyPluginState>;
@@ -73,6 +73,7 @@ export interface TablePluginState {
73
73
  isBreakoutEnabled?: boolean;
74
74
  wasFullWidthModeEnabled?: boolean;
75
75
  isTableResizingEnabled?: boolean;
76
+ isDragAndDropEnabled?: boolean;
76
77
  }
77
78
  export type TablePluginAction = {
78
79
  type: 'SET_EDITOR_FOCUS';
@@ -18,3 +18,9 @@ export declare const hasResizeHandler: ({ columnEndIndexTarget, target, }: {
18
18
  columnEndIndexTarget: number;
19
19
  target: HTMLElement;
20
20
  }) => boolean;
21
+ export type TableDOMElements = {
22
+ wrapper: HTMLDivElement;
23
+ table: HTMLTableElement;
24
+ };
25
+ export declare const getTree: (tr: HTMLTableRowElement) => TableDOMElements | null;
26
+ export declare const getTop: (element: HTMLElement | Window | undefined) => number;
@@ -1,6 +1,6 @@
1
1
  export { getSelectedColumnIndexes, getSelectedRowIndexes, normalizeSelection, isSelectionUpdated, } from './selection';
2
2
  export { findControlsHoverDecoration, createControlsHoverDecoration, createColumnControlsDecoration, createColumnSelectedDecoration, createCellHoverDecoration, updateDecorations, createResizeHandleDecoration, createColumnLineResize, } from './decoration';
3
- export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, } from './nodes';
3
+ export { isIsolating, containsHeaderColumn, containsHeaderRow, checkIfHeaderColumnEnabled, checkIfHeaderRowEnabled, checkIfNumberColumnEnabled, isLayoutSupported, getTableWidth, tablesHaveDifferentColumnWidths, tablesHaveDifferentNoOfColumns, isTableNested, anyChildCellMergedAcrossRow, supportedHeaderRow, } from './nodes';
4
4
  export { unwrapContentFromTable, removeTableFromFirstChild, removeTableFromLastChild, transformSliceToRemoveOpenTable, transformSliceToCorrectEmptyTableCells, transformSliceToFixHardBreakProblemOnCopyFromCell, } from './paste';
5
5
  export { isCell, isCornerButton, isInsertRowButton, isColumnControlsDecorations, isTableControlsButton, isTableContainerOrWrapper, isRowControlsButton, getColumnOrRowIndex, getMousePositionHorizontalRelativeByElement, getMousePositionVerticalRelativeByElement, updateResizeHandles, isResizeHandleDecoration, hasResizeHandler, } from './dom';
6
6
  export { getColumnsWidths, isColumnDeleteButtonVisible, getColumnDeleteButtonParams, getColumnClassNames, } from './column-controls';
@@ -1,5 +1,5 @@
1
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
1
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  export declare const isIsolating: (node: PmNode) => boolean;
4
4
  export declare const containsHeaderColumn: (table: PmNode) => boolean;
5
5
  export declare const containsHeaderRow: (table: PmNode) => boolean;
@@ -11,3 +11,13 @@ export declare const getTableWidth: (node: PmNode) => number;
11
11
  export declare const tablesHaveDifferentColumnWidths: (currentTable: PmNode, previousTable: PmNode) => boolean;
12
12
  export declare const tablesHaveDifferentNoOfColumns: (currentTable: PmNode, previousTable: PmNode) => boolean;
13
13
  export declare const isTableNested: (state: EditorState, tablePos?: number) => boolean;
14
+ export declare const anyChildCellMergedAcrossRow: (node: PmNode) => boolean;
15
+ /**
16
+ * Check if a given node is a header row with this definition:
17
+ * - all children are tableHeader cells
18
+ * - no table cells have been have merged with other table row cells
19
+ *
20
+ * @param node ProseMirror node
21
+ * @return boolean if it meets definition
22
+ */
23
+ export declare const supportedHeaderRow: (node: PmNode) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,7 +32,7 @@ import {
32
32
  } from '@atlaskit/editor-test-helpers/doc-builder';
33
33
 
34
34
  import tablePlugin from '../../../plugins/table-plugin';
35
- import TableCellViews from '../../../plugins/table/nodeviews/tableCell';
35
+ import TableCell from '../../../plugins/table/nodeviews/TableCell';
36
36
  import { pluginKey } from '../../../plugins/table/pm-plugins/plugin-key';
37
37
  import type { PluginConfig } from '../../../plugins/table/types';
38
38
 
@@ -121,7 +121,7 @@ describe('table -> nodeviews -> tableCell.tsx', () => {
121
121
  const { state, dispatch } = editorView;
122
122
  const cell = findCellClosestToPos(state.doc.resolve(pos))!;
123
123
  const background = tableBackgroundColorNames.get('red');
124
- const updateSpy = jest.spyOn(TableCellViews.prototype, 'update');
124
+ const updateSpy = jest.spyOn(TableCell.prototype, 'update');
125
125
  dispatch(setCellAttrs(cell, { background })(state.tr));
126
126
  expect(updateSpy).toHaveReturnedWith(true);
127
127
  const cellDomNode = document.querySelector('td')!;