@atlaskit/editor-plugin-table 5.1.0 → 5.2.1

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 (81) hide show
  1. package/CHANGELOG.md +12 -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} +363 -303
  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/types.js +4 -1
  10. package/dist/cjs/plugins/table/utils/dom.js +31 -1
  11. package/dist/cjs/plugins/table/utils/index.js +12 -0
  12. package/dist/cjs/plugins/table/utils/nodes.js +31 -7
  13. package/dist/es2019/plugins/table/index.js +3 -2
  14. package/dist/es2019/plugins/table/nodeviews/{tableCell.js → TableCell.js} +28 -24
  15. package/dist/es2019/plugins/table/nodeviews/TableNodeViewBase.js +22 -0
  16. package/dist/es2019/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +324 -280
  17. package/dist/es2019/plugins/table/pm-plugins/main.js +8 -8
  18. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
  19. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
  20. package/dist/es2019/plugins/table/types.js +5 -1
  21. package/dist/es2019/plugins/table/utils/dom.js +30 -0
  22. package/dist/es2019/plugins/table/utils/index.js +1 -1
  23. package/dist/es2019/plugins/table/utils/nodes.js +16 -0
  24. package/dist/esm/plugins/table/index.js +3 -2
  25. package/dist/esm/plugins/table/nodeviews/TableCell.js +105 -0
  26. package/dist/esm/plugins/table/nodeviews/TableNodeViewBase.js +24 -0
  27. package/dist/esm/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.js → nodeviews/TableRow.js} +364 -303
  28. package/dist/esm/plugins/table/pm-plugins/main.js +16 -13
  29. package/dist/esm/plugins/table/pm-plugins/sticky-headers/index.js +1 -2
  30. package/dist/esm/plugins/table/pm-plugins/sticky-headers/plugin.js +1 -9
  31. package/dist/esm/plugins/table/types.js +5 -1
  32. package/dist/esm/plugins/table/utils/dom.js +30 -0
  33. package/dist/esm/plugins/table/utils/index.js +1 -1
  34. package/dist/esm/plugins/table/utils/nodes.js +24 -0
  35. package/dist/types/plugins/table/nodeviews/TableCell.d.ts +13 -0
  36. package/dist/types/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
  37. package/dist/types/plugins/table/nodeviews/TableRow.d.ts +62 -0
  38. package/dist/types/plugins/table/pm-plugins/main.d.ts +1 -1
  39. package/dist/types/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
  40. package/dist/types/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
  41. package/dist/types/plugins/table/types.d.ts +15 -0
  42. package/dist/types/plugins/table/utils/dom.d.ts +6 -0
  43. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  44. package/dist/types/plugins/table/utils/nodes.d.ts +12 -2
  45. package/dist/types-ts4.5/plugins/table/nodeviews/TableCell.d.ts +13 -0
  46. package/dist/types-ts4.5/plugins/table/nodeviews/TableNodeViewBase.d.ts +18 -0
  47. package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +62 -0
  48. package/dist/types-ts4.5/plugins/table/pm-plugins/main.d.ts +1 -1
  49. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -1
  50. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +1 -1
  51. package/dist/types-ts4.5/plugins/table/types.d.ts +15 -0
  52. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +6 -0
  53. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  54. package/dist/types-ts4.5/plugins/table/utils/nodes.d.ts +12 -2
  55. package/package.json +4 -2
  56. package/src/__tests__/unit/nodeviews/cell.ts +2 -2
  57. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +25 -148
  58. package/src/plugins/table/index.tsx +2 -0
  59. package/src/plugins/table/nodeviews/{tableCell.tsx → TableCell.ts} +41 -46
  60. package/src/plugins/table/nodeviews/TableNodeViewBase.ts +32 -0
  61. package/src/plugins/table/{pm-plugins/sticky-headers/nodeviews/tableRow.ts → nodeviews/TableRow.ts} +246 -246
  62. package/src/plugins/table/pm-plugins/main.ts +10 -19
  63. package/src/plugins/table/pm-plugins/sticky-headers/index.ts +0 -1
  64. package/src/plugins/table/pm-plugins/sticky-headers/plugin.ts +1 -9
  65. package/src/plugins/table/types.ts +18 -0
  66. package/src/plugins/table/utils/dom.ts +38 -0
  67. package/src/plugins/table/utils/index.ts +2 -0
  68. package/src/plugins/table/utils/nodes.ts +30 -2
  69. package/tsconfig.app.json +6 -0
  70. package/dist/cjs/plugins/table/nodeviews/tableCell.js +0 -99
  71. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -35
  72. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
  73. package/dist/esm/plugins/table/nodeviews/tableCell.js +0 -93
  74. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.js +0 -29
  75. package/dist/types/plugins/table/nodeviews/tableCell.d.ts +0 -17
  76. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  77. package/dist/types/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  78. package/dist/types-ts4.5/plugins/table/nodeviews/tableCell.d.ts +0 -17
  79. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  80. package/dist/types-ts4.5/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -73
  81. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.ts +0 -37
@@ -25,10 +25,8 @@ import {
25
25
  import type {
26
26
  GetEditorContainerWidth,
27
27
  GetEditorFeatureFlags,
28
- getPosHandler,
29
28
  } from '@atlaskit/editor-common/types';
30
29
  import { browser, closestElement } from '@atlaskit/editor-common/utils';
31
- import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
32
30
  import type {
33
31
  EditorState,
34
32
  TextSelection,
@@ -67,7 +65,8 @@ import {
67
65
  whenTableInFocus,
68
66
  } from '../event-handlers';
69
67
  import { createTableView } from '../nodeviews/table';
70
- import TableCellNodeView from '../nodeviews/tableCell';
68
+ import TableCell from '../nodeviews/TableCell';
69
+ import TableRow from '../nodeviews/TableRow';
71
70
  import { pluginKey as decorationsPluginKey } from '../pm-plugins/decorations/plugin';
72
71
  import { fixTables, replaceSelectedTable } from '../transforms';
73
72
  import type {
@@ -103,6 +102,7 @@ export const createPlugin = (
103
102
  fullWidthModeEnabled?: boolean,
104
103
  tableResizingEnabled?: boolean,
105
104
  previousFullWidthModeEnabled?: boolean,
105
+ dragAndDropEnabled?: boolean,
106
106
  editorAnalyticsAPI?: EditorAnalyticsAPI,
107
107
  pluginInjectionApi?: PluginInjectionAPI,
108
108
  ) => {
@@ -116,6 +116,7 @@ export const createPlugin = (
116
116
  isTableResizingEnabled: tableResizingEnabled,
117
117
  isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
118
118
  isHeaderColumnEnabled: false,
119
+ isDragAndDropEnabled: dragAndDropEnabled,
119
120
  ...defaultTableSelection,
120
121
  getIntl,
121
122
  });
@@ -133,19 +134,6 @@ export const createPlugin = (
133
134
  })
134
135
  : undefined;
135
136
 
136
- const tableCellNodeview = {
137
- tableCell: (
138
- node: ProseMirrorNode,
139
- view: EditorView,
140
- getPos: getPosHandler,
141
- ) => new TableCellNodeView(node, view, getPos, observer),
142
- tableHeader: (
143
- node: ProseMirrorNode,
144
- view: EditorView,
145
- getPos: getPosHandler,
146
- ) => new TableCellNodeView(node, view, getPos, observer),
147
- };
148
-
149
137
  // Used to prevent invalid table cell spans being reported more than once per editor/document
150
138
  const invalidTableIds: string[] = [];
151
139
  let editorViewRef: EditorView | null = null;
@@ -365,9 +353,7 @@ export const createPlugin = (
365
353
  }
366
354
  return false;
367
355
  },
368
-
369
356
  nodeViews: {
370
- ...tableCellNodeview,
371
357
  table: (node, view, getPos) =>
372
358
  createTableView(
373
359
  node,
@@ -379,8 +365,13 @@ export const createPlugin = (
379
365
  getEditorFeatureFlags,
380
366
  pluginInjectionApi,
381
367
  ),
368
+ tableRow: (node, view, getPos) =>
369
+ new TableRow(node, view, getPos, eventDispatcher),
370
+ tableCell: (node, view, getPos) =>
371
+ new TableCell(node, view, getPos, eventDispatcher, observer),
372
+ tableHeader: (node, view, getPos) =>
373
+ new TableCell(node, view, getPos, eventDispatcher, observer),
382
374
  },
383
-
384
375
  handleDOMEvents: {
385
376
  focus: handleFocus,
386
377
  blur: handleBlur,
@@ -4,4 +4,3 @@ export type { StickyPluginState, RowStickyState } from './types';
4
4
 
5
5
  export { findStickyHeaderForTable } from './util';
6
6
  export { updateStickyState, removeStickyState } from './commands';
7
- export { TableRowNodeView } from './nodeviews/tableRow';
@@ -1,11 +1,10 @@
1
- import {
1
+ import type {
2
2
  Dispatch,
3
3
  EventDispatcher,
4
4
  } from '@atlaskit/editor-common/event-dispatcher';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
6
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
7
7
 
8
- import { TableRowNodeView } from './nodeviews/tableRow';
9
8
  import { pluginKey } from './plugin-key';
10
9
  import { createPluginState } from './plugin-state';
11
10
 
@@ -18,12 +17,5 @@ export const createPlugin = (
18
17
  return new SafePlugin({
19
18
  state: createPluginState(dispatch, initialState),
20
19
  key: pluginKey,
21
- props: {
22
- nodeViews: {
23
- tableRow: (node, view, getPos) => {
24
- return new TableRowNodeView(node, view, getPos, eventDispatcher);
25
- },
26
- },
27
- },
28
20
  });
29
21
  };
@@ -121,6 +121,8 @@ export interface TablePluginState {
121
121
  isBreakoutEnabled?: boolean;
122
122
  wasFullWidthModeEnabled?: boolean;
123
123
  isTableResizingEnabled?: boolean;
124
+
125
+ isDragAndDropEnabled?: boolean;
124
126
  }
125
127
 
126
128
  export type TablePluginAction =
@@ -365,3 +367,19 @@ export type InvalidNodeAttr = {
365
367
  spanValue: number;
366
368
  tableLocalId: string;
367
369
  };
370
+
371
+ /**
372
+ * Drag and Drop interfaces
373
+ */
374
+ export type DraggableType = 'table-row' | 'table-column';
375
+ export interface DraggableSourceData extends Record<string, unknown> {
376
+ type: DraggableType;
377
+ localId: string;
378
+ indexes: number[];
379
+ }
380
+
381
+ export interface DraggableTargetData extends Record<string, unknown> {
382
+ type: DraggableType;
383
+ localId: string;
384
+ targetIndex: number;
385
+ }
@@ -203,3 +203,41 @@ export const hasResizeHandler = ({
203
203
 
204
204
  return true;
205
205
  };
206
+
207
+ export type TableDOMElements = {
208
+ wrapper: HTMLDivElement;
209
+ table: HTMLTableElement;
210
+ };
211
+
212
+ export const getTree = (tr: HTMLTableRowElement): TableDOMElements | null => {
213
+ // pm renders into tbody, owned by react
214
+ const tbody = tr.parentElement;
215
+ if (!tbody) {
216
+ return null;
217
+ }
218
+
219
+ // rendered by react
220
+ const table = tbody.parentElement;
221
+ if (!table) {
222
+ return null;
223
+ }
224
+
225
+ // rendered by react
226
+ const wrapper = table.parentElement;
227
+ if (!wrapper) {
228
+ return null;
229
+ }
230
+
231
+ return {
232
+ wrapper: wrapper as HTMLDivElement,
233
+ table: table as HTMLTableElement,
234
+ };
235
+ };
236
+
237
+ export const getTop = (element: HTMLElement | Window | undefined): number => {
238
+ if (!element || element instanceof Window) {
239
+ return 0;
240
+ }
241
+
242
+ return element?.getBoundingClientRect?.()?.top ?? 0;
243
+ };
@@ -26,6 +26,8 @@ export {
26
26
  tablesHaveDifferentColumnWidths,
27
27
  tablesHaveDifferentNoOfColumns,
28
28
  isTableNested,
29
+ anyChildCellMergedAcrossRow,
30
+ supportedHeaderRow,
29
31
  } from './nodes';
30
32
  export {
31
33
  unwrapContentFromTable,
@@ -1,5 +1,9 @@
1
- import { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
1
+ import { mapChildren } from '@atlaskit/editor-common/utils';
2
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
+ import type {
4
+ EditorState,
5
+ Selection,
6
+ } from '@atlaskit/editor-prosemirror/state';
3
7
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
9
  import { findTable } from '@atlaskit/editor-tables/utils';
@@ -149,3 +153,27 @@ export const isTableNested = (state: EditorState, tablePos = 0): boolean => {
149
153
  parent.type === nodeTypes.bodiedExtension
150
154
  );
151
155
  };
156
+
157
+ export const anyChildCellMergedAcrossRow = (node: PmNode): boolean =>
158
+ mapChildren(node, (child) => child.attrs.rowspan || 0).some(
159
+ (rowspan) => rowspan > 1,
160
+ );
161
+
162
+ /**
163
+ * Check if a given node is a header row with this definition:
164
+ * - all children are tableHeader cells
165
+ * - no table cells have been have merged with other table row cells
166
+ *
167
+ * @param node ProseMirror node
168
+ * @return boolean if it meets definition
169
+ */
170
+ export const supportedHeaderRow = (node: PmNode): boolean => {
171
+ const allHeaders = mapChildren(
172
+ node,
173
+ (child) => child.type.name === 'tableHeader',
174
+ ).every(Boolean);
175
+
176
+ const someMerged = anyChildCellMergedAcrossRow(node);
177
+
178
+ return allHeaders && !someMerged;
179
+ };
package/tsconfig.app.json CHANGED
@@ -69,6 +69,12 @@
69
69
  {
70
70
  "path": "../../platform/feature-flags/tsconfig.app.json"
71
71
  },
72
+ {
73
+ "path": "../../pragmatic-drag-and-drop/core/tsconfig.app.json"
74
+ },
75
+ {
76
+ "path": "../../pragmatic-drag-and-drop/hitbox/tsconfig.app.json"
77
+ },
72
78
  {
73
79
  "path": "../../design-system/theme/tsconfig.app.json"
74
80
  },
@@ -1,99 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _uuid = _interopRequireDefault(require("uuid"));
12
- var _adfSchema = require("@atlaskit/adf-schema");
13
- var _model = require("@atlaskit/editor-prosemirror/model");
14
- var DEFAULT_COL_SPAN = 1;
15
- var DEFAULT_ROW_SPAN = 1;
16
- var TableCellNodeView = exports.default = /*#__PURE__*/function () {
17
- function TableCellNodeView(node, view, getPos, observer) {
18
- (0, _classCallCheck2.default)(this, TableCellNodeView);
19
- this.view = view;
20
- this.node = node;
21
- var _DOMSerializer$render = _model.DOMSerializer.renderSpec(document, node.type.spec.toDOM(node)),
22
- dom = _DOMSerializer$render.dom,
23
- contentDOM = _DOMSerializer$render.contentDOM;
24
- this.getPos = getPos;
25
- this.dom = dom;
26
- this.contentDOM = contentDOM;
27
- if (observer) {
28
- this.contentDOM.id = (0, _uuid.default)();
29
- this.observer = observer;
30
- observer.observe(this.contentDOM);
31
- }
32
- }
33
- (0, _createClass2.default)(TableCellNodeView, [{
34
- key: "updateNodeView",
35
- value: function updateNodeView(node) {
36
- var _this = this;
37
- if (this.node.type !== node.type) {
38
- return false;
39
- }
40
- var attrs = (0, _adfSchema.getCellDomAttrs)(this.node);
41
- var nextAttrs = (0, _adfSchema.getCellDomAttrs)(node);
42
- var _getCellAttrs = (0, _adfSchema.getCellAttrs)(this.dom),
43
- colspan = _getCellAttrs.colspan,
44
- rowspan = _getCellAttrs.rowspan;
45
-
46
- // need to rerender when colspan/rowspan in dom are different from the node attrs
47
- // this can happen when undoing merge cells
48
- if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
49
- return false;
50
- }
51
-
52
- // added + changed attributes
53
- var addedAttrs = Object.entries(nextAttrs).filter(function (_ref) {
54
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
55
- key = _ref2[0],
56
- value = _ref2[1];
57
- return attrs[key] !== value;
58
- });
59
- var removedAttrs = Object.keys(attrs).filter(function (key) {
60
- return !nextAttrs.hasOwnProperty(key);
61
- });
62
- if (addedAttrs.length || removedAttrs.length) {
63
- addedAttrs.forEach(function (_ref3) {
64
- var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
65
- key = _ref4[0],
66
- value = _ref4[1];
67
- return _this.dom.setAttribute(key, value || '');
68
- });
69
- removedAttrs.forEach(function (key) {
70
- return _this.dom.removeAttribute(key);
71
- });
72
- return true;
73
- }
74
-
75
- // Return true to not re-render this node view
76
- if (this.node.sameMarkup(node)) {
77
- return true;
78
- }
79
- return false;
80
- }
81
- }, {
82
- key: "update",
83
- value: function update(node) {
84
- var didUpdate = this.updateNodeView(node);
85
- if (didUpdate) {
86
- this.node = node;
87
- }
88
- return didUpdate;
89
- }
90
- }, {
91
- key: "destroy",
92
- value: function destroy() {
93
- if (this.observer) {
94
- this.observer.unobserve(this.contentDOM);
95
- }
96
- }
97
- }]);
98
- return TableCellNodeView;
99
- }();
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTree = exports.getTop = void 0;
7
- var getTree = exports.getTree = function getTree(tr) {
8
- // pm renders into tbody, owned by react
9
- var tbody = tr.parentElement;
10
- if (!tbody) {
11
- return null;
12
- }
13
-
14
- // rendered by react
15
- var table = tbody.parentElement;
16
- if (!table) {
17
- return null;
18
- }
19
-
20
- // rendered by react
21
- var wrapper = table.parentElement;
22
- if (!wrapper) {
23
- return null;
24
- }
25
- return {
26
- wrapper: wrapper,
27
- table: table
28
- };
29
- };
30
- var getTop = exports.getTop = function getTop(element) {
31
- if (!element || element instanceof Window) {
32
- return 0;
33
- }
34
- return element.getBoundingClientRect().top;
35
- };
@@ -1,29 +0,0 @@
1
- export const getTree = tr => {
2
- // pm renders into tbody, owned by react
3
- const tbody = tr.parentElement;
4
- if (!tbody) {
5
- return null;
6
- }
7
-
8
- // rendered by react
9
- const table = tbody.parentElement;
10
- if (!table) {
11
- return null;
12
- }
13
-
14
- // rendered by react
15
- const wrapper = table.parentElement;
16
- if (!wrapper) {
17
- return null;
18
- }
19
- return {
20
- wrapper: wrapper,
21
- table: table
22
- };
23
- };
24
- export const getTop = element => {
25
- if (!element || element instanceof Window) {
26
- return 0;
27
- }
28
- return element.getBoundingClientRect().top;
29
- };
@@ -1,93 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import uuid from 'uuid';
5
- import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
6
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
7
- var DEFAULT_COL_SPAN = 1;
8
- var DEFAULT_ROW_SPAN = 1;
9
- var TableCellNodeView = /*#__PURE__*/function () {
10
- function TableCellNodeView(node, view, getPos, observer) {
11
- _classCallCheck(this, TableCellNodeView);
12
- this.view = view;
13
- this.node = node;
14
- var _DOMSerializer$render = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node)),
15
- dom = _DOMSerializer$render.dom,
16
- contentDOM = _DOMSerializer$render.contentDOM;
17
- this.getPos = getPos;
18
- this.dom = dom;
19
- this.contentDOM = contentDOM;
20
- if (observer) {
21
- this.contentDOM.id = uuid();
22
- this.observer = observer;
23
- observer.observe(this.contentDOM);
24
- }
25
- }
26
- _createClass(TableCellNodeView, [{
27
- key: "updateNodeView",
28
- value: function updateNodeView(node) {
29
- var _this = this;
30
- if (this.node.type !== node.type) {
31
- return false;
32
- }
33
- var attrs = getCellDomAttrs(this.node);
34
- var nextAttrs = getCellDomAttrs(node);
35
- var _getCellAttrs = getCellAttrs(this.dom),
36
- colspan = _getCellAttrs.colspan,
37
- rowspan = _getCellAttrs.rowspan;
38
-
39
- // need to rerender when colspan/rowspan in dom are different from the node attrs
40
- // this can happen when undoing merge cells
41
- if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
42
- return false;
43
- }
44
-
45
- // added + changed attributes
46
- var addedAttrs = Object.entries(nextAttrs).filter(function (_ref) {
47
- var _ref2 = _slicedToArray(_ref, 2),
48
- key = _ref2[0],
49
- value = _ref2[1];
50
- return attrs[key] !== value;
51
- });
52
- var removedAttrs = Object.keys(attrs).filter(function (key) {
53
- return !nextAttrs.hasOwnProperty(key);
54
- });
55
- if (addedAttrs.length || removedAttrs.length) {
56
- addedAttrs.forEach(function (_ref3) {
57
- var _ref4 = _slicedToArray(_ref3, 2),
58
- key = _ref4[0],
59
- value = _ref4[1];
60
- return _this.dom.setAttribute(key, value || '');
61
- });
62
- removedAttrs.forEach(function (key) {
63
- return _this.dom.removeAttribute(key);
64
- });
65
- return true;
66
- }
67
-
68
- // Return true to not re-render this node view
69
- if (this.node.sameMarkup(node)) {
70
- return true;
71
- }
72
- return false;
73
- }
74
- }, {
75
- key: "update",
76
- value: function update(node) {
77
- var didUpdate = this.updateNodeView(node);
78
- if (didUpdate) {
79
- this.node = node;
80
- }
81
- return didUpdate;
82
- }
83
- }, {
84
- key: "destroy",
85
- value: function destroy() {
86
- if (this.observer) {
87
- this.observer.unobserve(this.contentDOM);
88
- }
89
- }
90
- }]);
91
- return TableCellNodeView;
92
- }();
93
- export { TableCellNodeView as default };
@@ -1,29 +0,0 @@
1
- export var getTree = function getTree(tr) {
2
- // pm renders into tbody, owned by react
3
- var tbody = tr.parentElement;
4
- if (!tbody) {
5
- return null;
6
- }
7
-
8
- // rendered by react
9
- var table = tbody.parentElement;
10
- if (!table) {
11
- return null;
12
- }
13
-
14
- // rendered by react
15
- var wrapper = table.parentElement;
16
- if (!wrapper) {
17
- return null;
18
- }
19
- return {
20
- wrapper: wrapper,
21
- table: table
22
- };
23
- };
24
- export var getTop = function getTop(element) {
25
- if (!element || element instanceof Window) {
26
- return 0;
27
- }
28
- return element.getBoundingClientRect().top;
29
- };
@@ -1,17 +0,0 @@
1
- import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
2
- import type { getPosHandler } from '@atlaskit/editor-common/types';
3
- import { Node } from '@atlaskit/editor-prosemirror/model';
4
- import { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
5
- export default class TableCellNodeView implements NodeView {
6
- node: Node;
7
- dom: HTMLElement;
8
- contentDOM: HTMLElement;
9
- getPos: getPosHandler;
10
- view: EditorView;
11
- providerFactory?: ProviderFactory;
12
- observer?: ResizeObserver;
13
- constructor(node: Node, view: EditorView, getPos: any, observer?: ResizeObserver);
14
- private updateNodeView;
15
- update(node: Node): boolean;
16
- destroy(): void;
17
- }
@@ -1,6 +0,0 @@
1
- export type TableDOMElements = {
2
- wrapper: HTMLDivElement;
3
- table: HTMLTableElement;
4
- };
5
- export declare const getTree: (tr: HTMLTableRowElement) => TableDOMElements | null;
6
- export declare const getTop: (element: HTMLElement | Window | undefined) => number;
@@ -1,73 +0,0 @@
1
- /// <reference types="lodash" />
2
- import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
3
- import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
- import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
5
- import type { TablePluginState } from '../../../types';
6
- import type { TableDOMElements } from './dom';
7
- /**
8
- * Check if a given node is a header row with this definition:
9
- * - all children are tableHeader cells
10
- * - no table cells have been have merged with other table row cells
11
- *
12
- * @param node ProseMirror node
13
- * @return boolean if it meets definition
14
- */
15
- export declare const supportedHeaderRow: (node: PmNode) => boolean;
16
- export declare class TableRowNodeView implements NodeView {
17
- view: EditorView;
18
- node: PmNode;
19
- getPos: () => number;
20
- eventDispatcher: EventDispatcher;
21
- dom: HTMLTableRowElement;
22
- contentDOM: HTMLElement;
23
- isHeaderRow: boolean;
24
- editorScrollableElement?: HTMLElement | Window;
25
- colControlsOffset: number;
26
- focused: boolean;
27
- topPosEditorElement: number;
28
- isSticky: boolean;
29
- lastStickyTimestamp: number | undefined;
30
- lastTimePainted: number;
31
- private intersectionObserver?;
32
- private resizeObserver?;
33
- private sentinels;
34
- private stickyRowHeight?;
35
- get tree(): TableDOMElements | null | undefined;
36
- constructor(node: PmNode, view: EditorView, getPos: any, eventDispatcher: EventDispatcher);
37
- listening: boolean;
38
- headerRowMouseScrollEnd: import("lodash").DebouncedFunc<() => void>;
39
- headerRowMouseScroll: import("lodash").DebouncedFunc<() => void>;
40
- subscribe(): void;
41
- unsubscribe(): void;
42
- private initObservers;
43
- private createResizeObserver;
44
- private createIntersectionObserver;
45
- previousDomTop: number | undefined;
46
- previousPadding: number | undefined;
47
- latestDomTop: number | undefined;
48
- nextFrame: number | undefined;
49
- update(node: PmNode, ..._args: any[]): boolean;
50
- destroy(): void;
51
- ignoreMutation(mutationRecord: MutationRecord | {
52
- type: 'selection';
53
- target: Element;
54
- }): boolean;
55
- onTablePluginState: (state: TablePluginState) => void;
56
- updateStickyHeaderWidth: () => void;
57
- shouldHeaderStick: (tree: TableDOMElements) => boolean;
58
- /**
59
- * Manually refire the intersection observers.
60
- * Useful when the header may have detached from the table.
61
- */
62
- refireIntersectionObservers: () => void;
63
- makeHeaderRowSticky: (tree: TableDOMElements, scrollTop?: number) => void;
64
- makeRowHeaderNotSticky: (table: HTMLElement, isEditorDestroyed?: boolean) => void;
65
- getWrapperoffset: (inverse?: boolean) => number;
66
- getWrapperRefTop: (wrapper: HTMLElement) => number;
67
- getScrolledTableTop: (wrapper: HTMLElement) => number;
68
- getCurrentTableTop: (tree: TableDOMElements) => number;
69
- padding: number;
70
- top: number;
71
- emitOn: (top: number, padding: number) => void;
72
- emitOff: (isEditorDestroyed: boolean) => void;
73
- }
@@ -1,17 +0,0 @@
1
- import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
2
- import type { getPosHandler } from '@atlaskit/editor-common/types';
3
- import { Node } from '@atlaskit/editor-prosemirror/model';
4
- import { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
5
- export default class TableCellNodeView implements NodeView {
6
- node: Node;
7
- dom: HTMLElement;
8
- contentDOM: HTMLElement;
9
- getPos: getPosHandler;
10
- view: EditorView;
11
- providerFactory?: ProviderFactory;
12
- observer?: ResizeObserver;
13
- constructor(node: Node, view: EditorView, getPos: any, observer?: ResizeObserver);
14
- private updateNodeView;
15
- update(node: Node): boolean;
16
- destroy(): void;
17
- }
@@ -1,6 +0,0 @@
1
- export type TableDOMElements = {
2
- wrapper: HTMLDivElement;
3
- table: HTMLTableElement;
4
- };
5
- export declare const getTree: (tr: HTMLTableRowElement) => TableDOMElements | null;
6
- export declare const getTop: (element: HTMLElement | Window | undefined) => number;