@atlaskit/editor-plugin-table 7.9.0 → 7.10.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 (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/commands/column-resize.js +25 -7
  3. package/dist/cjs/nodeviews/TableComponent.js +11 -3
  4. package/dist/cjs/nodeviews/TableRow.js +1 -1
  5. package/dist/cjs/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  6. package/dist/cjs/pm-plugins/table-resizing/utils/misc.js +1 -1
  7. package/dist/cjs/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  8. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  9. package/dist/cjs/transforms/column-width.js +3 -1
  10. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  11. package/dist/cjs/utils/index.js +12 -0
  12. package/dist/cjs/utils/nodes.js +6 -1
  13. package/dist/cjs/utils/table.js +34 -1
  14. package/dist/es2019/commands/column-resize.js +25 -7
  15. package/dist/es2019/nodeviews/TableComponent.js +12 -4
  16. package/dist/es2019/nodeviews/TableRow.js +1 -1
  17. package/dist/es2019/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  18. package/dist/es2019/pm-plugins/table-resizing/utils/misc.js +1 -1
  19. package/dist/es2019/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  20. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  21. package/dist/es2019/transforms/column-width.js +3 -1
  22. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  23. package/dist/es2019/utils/index.js +2 -2
  24. package/dist/es2019/utils/nodes.js +5 -0
  25. package/dist/es2019/utils/table.js +36 -1
  26. package/dist/esm/commands/column-resize.js +25 -7
  27. package/dist/esm/nodeviews/TableComponent.js +12 -4
  28. package/dist/esm/nodeviews/TableRow.js +1 -1
  29. package/dist/esm/pm-plugins/table-resizing/utils/colgroup.js +4 -4
  30. package/dist/esm/pm-plugins/table-resizing/utils/misc.js +1 -1
  31. package/dist/esm/pm-plugins/table-resizing/utils/resize-column.js +5 -3
  32. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +9 -7
  33. package/dist/esm/transforms/column-width.js +3 -1
  34. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +19 -6
  35. package/dist/esm/utils/index.js +2 -2
  36. package/dist/esm/utils/nodes.js +5 -0
  37. package/dist/esm/utils/table.js +33 -0
  38. package/dist/types/commands/column-resize.d.ts +5 -4
  39. package/dist/types/nodeviews/TableComponent.d.ts +6 -54
  40. package/dist/types/plugin.d.ts +1 -1
  41. package/dist/types/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  42. package/dist/types/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  43. package/dist/types/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  44. package/dist/types/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  45. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -20
  46. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +32 -40
  47. package/dist/types/ui/TableFloatingControls/index.d.ts +16 -20
  48. package/dist/types/utils/index.d.ts +2 -2
  49. package/dist/types/utils/nodes.d.ts +1 -0
  50. package/dist/types/utils/table.d.ts +3 -0
  51. package/dist/types-ts4.5/commands/column-resize.d.ts +5 -4
  52. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +6 -54
  53. package/dist/types-ts4.5/plugin.d.ts +1 -1
  54. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/colgroup.d.ts +1 -1
  55. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/misc.d.ts +1 -1
  56. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-column.d.ts +1 -1
  57. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/resize-state.d.ts +2 -2
  58. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +16 -20
  59. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +32 -40
  60. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +16 -20
  61. package/dist/types-ts4.5/utils/index.d.ts +2 -2
  62. package/dist/types-ts4.5/utils/nodes.d.ts +1 -0
  63. package/dist/types-ts4.5/utils/table.d.ts +3 -0
  64. package/package.json +4 -1
  65. package/src/commands/column-resize.ts +42 -11
  66. package/src/nodeviews/TableComponent.tsx +21 -6
  67. package/src/nodeviews/TableRow.ts +2 -2
  68. package/src/plugin.tsx +1 -1
  69. package/src/pm-plugins/table-resizing/utils/colgroup.ts +5 -5
  70. package/src/pm-plugins/table-resizing/utils/misc.ts +2 -2
  71. package/src/pm-plugins/table-resizing/utils/resize-column.ts +7 -5
  72. package/src/pm-plugins/table-resizing/utils/resize-state.ts +16 -10
  73. package/src/transforms/column-width.ts +10 -2
  74. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +28 -11
  75. package/src/utils/index.ts +2 -1
  76. package/src/utils/nodes.ts +10 -0
  77. package/src/utils/table.ts +36 -0
@@ -8,6 +8,7 @@ import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
8
8
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
9
9
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
10
10
  import type { Rect } from '@atlaskit/editor-tables/table-map';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
12
 
12
13
  import { getSelectedTableInfo } from '../../../utils';
13
14
 
@@ -34,7 +35,7 @@ export const getResizeState = ({
34
35
  minWidth: number;
35
36
  maxSize: number;
36
37
  table: PMNode;
37
- tableRef: HTMLTableElement;
38
+ tableRef: HTMLTableElement | null;
38
39
  start: number;
39
40
  domAtPos: (pos: number) => { node: Node; offset: number };
40
41
  isTableScalingEnabled: boolean;
@@ -107,12 +108,12 @@ export const getResizeState = ({
107
108
  // updates Colgroup DOM node with new widths
108
109
  export const updateColgroup = (
109
110
  state: ResizeState,
110
- tableRef: HTMLElement,
111
+ tableRef: HTMLElement | null,
111
112
  tableNode?: PMNode,
112
113
  isTableScalingEnabled?: boolean,
113
114
  ): void => {
114
- const cols = tableRef.querySelectorAll('col');
115
- const columnsCount = cols.length;
115
+ const cols = tableRef?.querySelectorAll('col');
116
+ const columnsCount = cols?.length;
116
117
  /**
117
118
  updateColgroup will update whole table scale when click the column resize handle, this behavior will affect when table overflowed, when now resize handle been dragged and extend to make table overflowed, table will show overflow. This need to be confirmed because it conflict with how isTableScalingEnabled work.
118
119
  We don't want to scale the table when resizing columns, only when viewpoint shrinks the table.
@@ -123,11 +124,11 @@ export const updateColgroup = (
123
124
  state.cols
124
125
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
125
126
  .forEach((column, i) => {
126
- const fixedColWidth = getColWidthFix(column.width, columnsCount);
127
+ const fixedColWidth = getColWidthFix(column.width, columnsCount ?? 0);
127
128
  const scaledWidth = fixedColWidth * scalePercent;
128
129
  const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
129
130
  // we aren't handling the remaining pixels here when the 48px min width is reached
130
- if (cols[i]) {
131
+ if (cols?.[i]) {
131
132
  cols[i].style.width = `${finalWidth}px`;
132
133
  }
133
134
  });
@@ -135,10 +136,10 @@ export const updateColgroup = (
135
136
  state.cols
136
137
  .filter((column) => column && !!column.width) // if width is 0, we dont want to apply that.
137
138
  .forEach((column, i) => {
138
- if (cols[i]) {
139
+ if (cols?.[i]) {
139
140
  cols[i].style.width = `${getColWidthFix(
140
141
  column.width,
141
- columnsCount,
142
+ columnsCount ?? 0,
142
143
  )}px`;
143
144
  }
144
145
  });
@@ -361,8 +362,13 @@ export const getNewResizeStateFromSelectedColumns = (
361
362
  return;
362
363
  }
363
364
 
364
- const maybeTable = domAtPos(table.start).node as HTMLElement;
365
- const tableRef = maybeTable.closest('table');
365
+ const maybeTable = domAtPos(table.start).node;
366
+
367
+ const maybeTableElement =
368
+ maybeTable instanceof HTMLElement ? maybeTable : null;
369
+ const tableRef = getBooleanFF('platform.editor.explicit-html-element-check')
370
+ ? maybeTableElement?.closest('table')
371
+ : (maybeTable as HTMLElement)?.closest('table');
366
372
 
367
373
  if (!tableRef) {
368
374
  return;
@@ -6,6 +6,7 @@ import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
6
  import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import { TableMap } from '@atlaskit/editor-tables/table-map';
9
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
10
 
10
11
  import type { ResizeState } from '../pm-plugins/table-resizing/utils';
11
12
  import {
@@ -119,8 +120,15 @@ export const rescaleColumns =
119
120
 
120
121
  const newTable = tr.doc.nodeAt(table.pos);
121
122
  const domAtPos = view.domAtPos.bind(view);
122
- const maybeTable = domAtPos(table.start).node as HTMLElement;
123
- const tableRef = maybeTable.closest('table');
123
+ const maybeTable = domAtPos(table.start).node;
124
+ const maybeTableElement = getBooleanFF(
125
+ 'platform.editor.explicit-html-element-check',
126
+ )
127
+ ? maybeTable instanceof HTMLElement
128
+ ? maybeTable
129
+ : null
130
+ : (maybeTable as HTMLElement | null);
131
+ const tableRef = maybeTableElement?.closest('table');
124
132
 
125
133
  if (!tableRef || !newTable) {
126
134
  return tr;
@@ -16,6 +16,7 @@ import type { Selection } from '@atlaskit/editor-prosemirror/state';
16
16
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
17
  import { CellSelection } from '@atlaskit/editor-tables';
18
18
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
19
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
19
20
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
20
21
  import { token } from '@atlaskit/tokens';
21
22
 
@@ -142,19 +143,35 @@ const DragControlsComponent = ({
142
143
 
143
144
  const handleMouseMove = useCallback(
144
145
  (e: MouseEvent) => {
145
- const isParentDragControls = (e.nativeEvent.target as Element).closest(
146
- `.${ClassName.DRAG_ROW_CONTROLS}`,
147
- );
148
- const rowIndex = (e.nativeEvent.target as Element).getAttribute(
149
- 'data-start-index',
150
- );
146
+ if (getBooleanFF('platform.editor.explicit-html-element-check')) {
147
+ const target =
148
+ e.nativeEvent.target instanceof Element ? e.nativeEvent.target : null;
149
+ const isParentDragControls = target?.closest(
150
+ `.${ClassName.DRAG_ROW_CONTROLS}`,
151
+ );
152
+ const rowIndex = target?.getAttribute('data-start-index');
151
153
 
152
- // avoid updating if event target is not related
153
- if (!isParentDragControls || !rowIndex) {
154
- return;
155
- }
154
+ // avoid updating if event target is not related
155
+ if (!isParentDragControls || !rowIndex) {
156
+ return;
157
+ }
156
158
 
157
- updateCellHoverLocation(Number(rowIndex));
159
+ updateCellHoverLocation(Number(rowIndex));
160
+ } else {
161
+ const isParentDragControls = (e.nativeEvent.target as Element).closest(
162
+ `.${ClassName.DRAG_ROW_CONTROLS}`,
163
+ );
164
+ const rowIndex = (e.nativeEvent.target as Element).getAttribute(
165
+ 'data-start-index',
166
+ );
167
+
168
+ // avoid updating if event target is not related
169
+ if (!isParentDragControls || !rowIndex) {
170
+ return;
171
+ }
172
+
173
+ updateCellHoverLocation(Number(rowIndex));
174
+ }
158
175
  },
159
176
  [updateCellHoverLocation],
160
177
  );
@@ -26,6 +26,7 @@ export {
26
26
  getTableWidth,
27
27
  tablesHaveDifferentColumnWidths,
28
28
  tablesHaveDifferentNoOfColumns,
29
+ tablesHaveDifferentNoOfRows,
29
30
  isTableNested,
30
31
  anyChildCellMergedAcrossRow,
31
32
  supportedHeaderRow,
@@ -75,7 +76,7 @@ export {
75
76
  } from './row-controls';
76
77
  export type { RowParams } from './row-controls';
77
78
  export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
78
- export { getMergedCellsPositions } from './table';
79
+ export { getMergedCellsPositions, getAssistiveMessage } from './table';
79
80
  export { updatePluginStateDecorations } from './update-plugin-state-decorations';
80
81
  export {
81
82
  hasMergedCellsInColumn,
@@ -94,6 +94,16 @@ export const tablesHaveDifferentNoOfColumns = (
94
94
  return prevMap.width !== currentMap.width;
95
95
  };
96
96
 
97
+ export const tablesHaveDifferentNoOfRows = (
98
+ currentTable: PmNode,
99
+ previousTable: PmNode,
100
+ ): boolean => {
101
+ const prevMap = TableMap.get(previousTable);
102
+ const currentMap = TableMap.get(currentTable);
103
+
104
+ return prevMap.height !== currentMap.height;
105
+ };
106
+
97
107
  function filterNearSelection<T, U>(
98
108
  selection: Selection,
99
109
  findNode: (selection: Selection) => { pos: number; node: PmNode } | undefined,
@@ -1,3 +1,7 @@
1
+ import type { IntlShape } from 'react-intl-next';
2
+
3
+ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
4
+ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
1
5
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
6
  import type { Rect } from '@atlaskit/editor-tables/table-map';
3
7
  import { TableMap } from '@atlaskit/editor-tables/table-map';
@@ -30,3 +34,35 @@ export const colsToRect = (cols: Array<number>, noOfRows: number): Rect => ({
30
34
  top: 0,
31
35
  bottom: noOfRows,
32
36
  });
37
+
38
+ export const getAssistiveMessage = (
39
+ prevTableNode: PmNode,
40
+ currentTableNode: PmNode,
41
+ intl: IntlShape,
42
+ ) => {
43
+ const { formatMessage } = intl;
44
+ const prevTableMap = TableMap.get(prevTableNode);
45
+ const currentTableMap = TableMap.get(currentTableNode);
46
+
47
+ if (currentTableMap.width !== prevTableMap.width) {
48
+ const diff = Math.abs(currentTableMap.width - prevTableMap.width);
49
+ if (currentTableMap.width > prevTableMap.width) {
50
+ return formatMessage(messages.columnsAreInserted, { count: diff });
51
+ }
52
+ if (currentTableMap.width < prevTableMap.width) {
53
+ return formatMessage(messages.columnsAreRemoved, { count: diff });
54
+ }
55
+ }
56
+
57
+ if (currentTableMap.height !== prevTableMap.height) {
58
+ const diff = Math.abs(currentTableMap.height - prevTableMap.height);
59
+ if (currentTableMap.height > prevTableMap.height) {
60
+ return formatMessage(messages.rowsAreInserted, { count: diff });
61
+ }
62
+ if (currentTableMap.height < prevTableMap.height) {
63
+ return formatMessage(messages.rowsAreRemoved, { count: diff });
64
+ }
65
+ }
66
+
67
+ return '';
68
+ };