@atlaskit/editor-plugin-table 12.2.6 → 12.2.7

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 (204) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +4 -4
  3. package/afm-cc/tsconfig.json +0 -123
  4. package/afm-dev-agents/tsconfig.json +0 -123
  5. package/afm-jira/tsconfig.json +0 -123
  6. package/afm-passionfruit/tsconfig.json +0 -123
  7. package/afm-post-office/tsconfig.json +0 -123
  8. package/afm-rovo-extension/tsconfig.json +0 -123
  9. package/afm-townsquare/tsconfig.json +0 -123
  10. package/afm-volt/tsconfig.json +0 -114
  11. package/build/tsconfig.json +0 -23
  12. package/docs/0-intro.tsx +0 -57
  13. package/src/index.ts +0 -21
  14. package/src/nodeviews/ExternalDropTargets.tsx +0 -91
  15. package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
  16. package/src/nodeviews/TableCell.ts +0 -134
  17. package/src/nodeviews/TableComponent.tsx +0 -1590
  18. package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
  19. package/src/nodeviews/TableContainer.tsx +0 -926
  20. package/src/nodeviews/TableNodeViewBase.ts +0 -29
  21. package/src/nodeviews/TableResizer.tsx +0 -884
  22. package/src/nodeviews/TableRow.ts +0 -830
  23. package/src/nodeviews/TableStickyScrollbar.ts +0 -211
  24. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
  25. package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
  26. package/src/nodeviews/table-container-styles.ts +0 -9
  27. package/src/nodeviews/table-node-views.ts +0 -76
  28. package/src/nodeviews/table.tsx +0 -530
  29. package/src/nodeviews/toDOM.ts +0 -244
  30. package/src/nodeviews/types.ts +0 -36
  31. package/src/nodeviews/update-overflow-shadows.ts +0 -11
  32. package/src/pm-plugins/analytics/actions.ts +0 -21
  33. package/src/pm-plugins/analytics/commands.ts +0 -47
  34. package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
  35. package/src/pm-plugins/analytics/plugin-key.ts +0 -5
  36. package/src/pm-plugins/analytics/plugin.ts +0 -80
  37. package/src/pm-plugins/analytics/reducer.ts +0 -27
  38. package/src/pm-plugins/analytics/types.ts +0 -20
  39. package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
  40. package/src/pm-plugins/commands/clear.ts +0 -43
  41. package/src/pm-plugins/commands/collapse.ts +0 -17
  42. package/src/pm-plugins/commands/column-resize.ts +0 -478
  43. package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
  44. package/src/pm-plugins/commands/delete.ts +0 -42
  45. package/src/pm-plugins/commands/display-mode.ts +0 -18
  46. package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
  47. package/src/pm-plugins/commands/hover.ts +0 -242
  48. package/src/pm-plugins/commands/index.ts +0 -51
  49. package/src/pm-plugins/commands/insert.ts +0 -438
  50. package/src/pm-plugins/commands/misc.ts +0 -811
  51. package/src/pm-plugins/commands/referentiality.ts +0 -15
  52. package/src/pm-plugins/commands/selection.ts +0 -537
  53. package/src/pm-plugins/commands/sort.ts +0 -102
  54. package/src/pm-plugins/commands/split-cell.ts +0 -28
  55. package/src/pm-plugins/commands/toggle.ts +0 -109
  56. package/src/pm-plugins/create-plugin-config.ts +0 -17
  57. package/src/pm-plugins/decorations/plugin.ts +0 -107
  58. package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
  59. package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
  60. package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
  61. package/src/pm-plugins/decorations/utils/types.ts +0 -16
  62. package/src/pm-plugins/default-table-selection.ts +0 -14
  63. package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
  64. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
  65. package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
  66. package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
  67. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
  68. package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
  69. package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
  70. package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
  71. package/src/pm-plugins/drag-and-drop/types.ts +0 -18
  72. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
  73. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
  74. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
  75. package/src/pm-plugins/handlers.ts +0 -161
  76. package/src/pm-plugins/keymap.ts +0 -436
  77. package/src/pm-plugins/main.ts +0 -433
  78. package/src/pm-plugins/plugin-factory.ts +0 -42
  79. package/src/pm-plugins/plugin-key.ts +0 -8
  80. package/src/pm-plugins/reducer.ts +0 -145
  81. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
  82. package/src/pm-plugins/sticky-headers/commands.ts +0 -8
  83. package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
  84. package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
  85. package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
  86. package/src/pm-plugins/sticky-headers/types.ts +0 -20
  87. package/src/pm-plugins/sticky-headers/util.ts +0 -18
  88. package/src/pm-plugins/table-analytics.ts +0 -100
  89. package/src/pm-plugins/table-local-id.ts +0 -213
  90. package/src/pm-plugins/table-resizing/commands.ts +0 -116
  91. package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
  92. package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
  93. package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
  94. package/src/pm-plugins/table-resizing/plugin.ts +0 -94
  95. package/src/pm-plugins/table-resizing/reducer.ts +0 -37
  96. package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
  97. package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
  98. package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
  99. package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
  100. package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
  101. package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
  102. package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
  103. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
  104. package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
  105. package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
  106. package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
  107. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
  108. package/src/pm-plugins/table-selection-keymap.ts +0 -64
  109. package/src/pm-plugins/table-size-selector.ts +0 -39
  110. package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
  111. package/src/pm-plugins/table-width.ts +0 -153
  112. package/src/pm-plugins/transforms/column-width.ts +0 -249
  113. package/src/pm-plugins/transforms/delete-columns.ts +0 -281
  114. package/src/pm-plugins/transforms/delete-rows.ts +0 -154
  115. package/src/pm-plugins/transforms/fix-tables.ts +0 -249
  116. package/src/pm-plugins/transforms/merge.ts +0 -301
  117. package/src/pm-plugins/transforms/replace-table.ts +0 -38
  118. package/src/pm-plugins/transforms/split.ts +0 -90
  119. package/src/pm-plugins/utils/alignment.ts +0 -33
  120. package/src/pm-plugins/utils/analytics.ts +0 -238
  121. package/src/pm-plugins/utils/collapse.ts +0 -93
  122. package/src/pm-plugins/utils/column-controls.ts +0 -250
  123. package/src/pm-plugins/utils/create.ts +0 -64
  124. package/src/pm-plugins/utils/decoration.ts +0 -672
  125. package/src/pm-plugins/utils/dom.ts +0 -251
  126. package/src/pm-plugins/utils/drag-menu.tsx +0 -491
  127. package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
  128. package/src/pm-plugins/utils/guidelines.ts +0 -30
  129. package/src/pm-plugins/utils/merged-cells.ts +0 -239
  130. package/src/pm-plugins/utils/nodes.ts +0 -162
  131. package/src/pm-plugins/utils/paste.ts +0 -386
  132. package/src/pm-plugins/utils/row-controls.ts +0 -211
  133. package/src/pm-plugins/utils/selection.ts +0 -17
  134. package/src/pm-plugins/utils/snapping.ts +0 -136
  135. package/src/pm-plugins/utils/table.ts +0 -60
  136. package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
  137. package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
  138. package/src/pm-plugins/view-mode-sort/index.ts +0 -291
  139. package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
  140. package/src/pm-plugins/view-mode-sort/types.ts +0 -23
  141. package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
  142. package/src/tablePlugin.tsx +0 -971
  143. package/src/tablePluginType.ts +0 -102
  144. package/src/types/index.ts +0 -592
  145. package/src/ui/ColumnResizeWidget/index.tsx +0 -61
  146. package/src/ui/ContentComponent.tsx +0 -311
  147. package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
  148. package/src/ui/DragHandle/index.tsx +0 -391
  149. package/src/ui/DragPreview/index.tsx +0 -51
  150. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
  151. package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
  152. package/src/ui/FloatingContextualButton/index.tsx +0 -168
  153. package/src/ui/FloatingContextualButton/styles.ts +0 -69
  154. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
  155. package/src/ui/FloatingContextualMenu/index.tsx +0 -141
  156. package/src/ui/FloatingContextualMenu/styles.ts +0 -77
  157. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
  158. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
  159. package/src/ui/FloatingDeleteButton/index.tsx +0 -383
  160. package/src/ui/FloatingDeleteButton/types.ts +0 -3
  161. package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
  162. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
  163. package/src/ui/FloatingDragMenu/index.tsx +0 -136
  164. package/src/ui/FloatingDragMenu/styles.ts +0 -83
  165. package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
  166. package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
  167. package/src/ui/FloatingInsertButton/index.tsx +0 -314
  168. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
  169. package/src/ui/SizeSelector/index.tsx +0 -74
  170. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
  171. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
  172. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
  173. package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
  174. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
  175. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
  176. package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
  177. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
  178. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
  179. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
  180. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
  181. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
  182. package/src/ui/TableFloatingControls/index.tsx +0 -275
  183. package/src/ui/TableFullWidthLabel/index.tsx +0 -38
  184. package/src/ui/common-styles.ts +0 -1218
  185. package/src/ui/consts.ts +0 -109
  186. package/src/ui/event-handlers.ts +0 -662
  187. package/src/ui/global-styles.tsx +0 -55
  188. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
  189. package/src/ui/icons/AddColLeftIcon.tsx +0 -37
  190. package/src/ui/icons/AddColRightIcon.tsx +0 -37
  191. package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
  192. package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
  193. package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
  194. package/src/ui/icons/DragHandleIcon.tsx +0 -16
  195. package/src/ui/icons/DragInMotionIcon.tsx +0 -54
  196. package/src/ui/icons/MergeCellsIcon.tsx +0 -26
  197. package/src/ui/icons/MinimisedHandle.tsx +0 -15
  198. package/src/ui/icons/SortingIconWrapper.tsx +0 -43
  199. package/src/ui/icons/SplitCellIcon.tsx +0 -34
  200. package/src/ui/toolbar.tsx +0 -1153
  201. package/src/ui/ui-styles.ts +0 -960
  202. package/tsconfig.app.json +0 -135
  203. package/tsconfig.dev.json +0 -54
  204. package/tsconfig.json +0 -18
@@ -1,306 +0,0 @@
1
- import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
2
- import { calcTableColumnWidths, getFragmentBackingArray } from '@atlaskit/editor-common/utils';
3
- import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
4
- import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
5
- import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
6
- import { TableMap } from '@atlaskit/editor-tables/table-map';
7
-
8
- import {
9
- COLUMN_MIN_WIDTH,
10
- MAX_SCALING_PERCENT,
11
- MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
12
- } from './consts';
13
- import {
14
- getScalingPercentForTableWithoutWidth,
15
- getTableContainerElementWidth,
16
- getTableScalingPercent,
17
- } from './misc';
18
-
19
- type Col = Array<string | { [name: string]: string }>;
20
-
21
- /**
22
- * This ensures the combined width of the columns (and tbody) of table is always smaller or equal
23
- * than the table and table wrapper elements. This is necessary as there is no longer
24
- * padding on the .pm-table-wrapper, so all elements need to be the same width to avoid
25
- * overflow.
26
- */
27
- export const getColWidthFix = (colwidth: number, tableColumnCount: number) =>
28
- colwidth - 1 / tableColumnCount;
29
-
30
- const generateColStyle = (
31
- fixedColWidth: number,
32
- tableWidth: number,
33
- isCommentEditor?: boolean,
34
- isChromelessEditor?: boolean,
35
- isNested?: boolean,
36
- shouldUseIncreasedScalingPercent?: boolean,
37
- isNumberColumnEnabled?: boolean,
38
- isTableHasWidth?: boolean,
39
- hasTableBeenResized?: boolean,
40
- ) => {
41
- const maxScalingPercent = shouldUseIncreasedScalingPercent
42
- ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
43
- : MAX_SCALING_PERCENT;
44
- const maxScaledRatio = 1 - maxScalingPercent;
45
-
46
- const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
47
-
48
- // for nested tables, or chromeless editor, which used non resizable table container
49
- if (isNested || isChromelessEditor) {
50
- if (hasTableBeenResized) {
51
- return `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`;
52
- }
53
- return `width: ${tableCellMinWidth}px)`;
54
- }
55
- if (isFullPageEditor || (!isFullPageEditor && isTableHasWidth)) {
56
- const scaledPercent = isNumberColumnEnabled
57
- ? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
58
- : `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
59
- return `width: max(calc(${fixedColWidth}px * ${maxScaledRatio}), calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
60
- }
61
- // table resized to full-width in comment editor
62
- // it doesn't have a width attribute, and cols has been resized
63
- if (hasTableBeenResized) {
64
- const scaledPercent = isNumberColumnEnabled
65
- ? `calc(calc(var(--ak-editor-table-width) - ${akEditorTableNumberColumnWidth}px - 1px)/${tableWidth})`
66
- : `calc(calc(var(--ak-editor-table-width) - 1px)/${tableWidth})`;
67
- return `width: max(calc(${fixedColWidth} * ${scaledPercent}), ${tableCellMinWidth}px)`;
68
- }
69
- return `width: ${tableCellMinWidth}px`;
70
- };
71
-
72
- export const generateColgroupFromNode = (
73
- table: PmNode,
74
- isCommentEditor?: boolean,
75
- isChromelessEditor?: boolean,
76
- isNested?: boolean,
77
- isTableScalingEnabled?: boolean,
78
- shouldUseIncreasedScalingPercent?: boolean,
79
- ) => {
80
- const cols: Col[] = [];
81
- const map = TableMap.get(table);
82
- const isTableHasWidth = !!table.attrs.width;
83
- const isNumberColumnEnabled = table.attrs.isNumberColumnEnabled || false;
84
- const isFullPageEditor = !isChromelessEditor && !isCommentEditor;
85
-
86
- // Ignored via go/ees005
87
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
88
- table.content.firstChild!.content.forEach((cell) => {
89
- const colspan = cell.attrs.colspan || 1;
90
- // if the table has been resized
91
- if (Array.isArray(cell.attrs.colwidth)) {
92
- cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
93
- // existing logic for calculating the width of the column
94
- const fixedColWidth = getColWidthFix(width, map.width);
95
- const tableWidth =
96
- isFullPageEditor || (!isFullPageEditor && isTableHasWidth)
97
- ? getTableContainerElementWidth(table)
98
- : calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
99
- if (isTableScalingEnabled) {
100
- cols.push([
101
- 'col',
102
- {
103
- style: generateColStyle(
104
- fixedColWidth,
105
- tableWidth,
106
- isCommentEditor,
107
- isChromelessEditor,
108
- isNested,
109
- shouldUseIncreasedScalingPercent,
110
- isNumberColumnEnabled,
111
- isTableHasWidth,
112
- true,
113
- ),
114
- },
115
- ]);
116
- } else {
117
- cols.push([
118
- 'col',
119
- {
120
- style: `width: max(${fixedColWidth}px, ${tableCellMinWidth}px)`,
121
- },
122
- ]);
123
- }
124
- });
125
- } else {
126
- // columns has not been resized, so distribute the width evenly
127
- cols.push(
128
- ...Array.from({ length: colspan }, (_) => {
129
- const tableWidth = getTableContainerElementWidth(table);
130
- const columnWidth = tableWidth / map.width || 0;
131
- const fixedColWidth = getColWidthFix(columnWidth, map.width || 0);
132
-
133
- return [
134
- 'col',
135
- {
136
- style: generateColStyle(
137
- fixedColWidth,
138
- tableWidth,
139
- isCommentEditor,
140
- isChromelessEditor,
141
- isNested,
142
- shouldUseIncreasedScalingPercent,
143
- isNumberColumnEnabled,
144
- isTableHasWidth,
145
- ),
146
- },
147
- ];
148
- }),
149
- );
150
- }
151
- });
152
- return cols;
153
- };
154
-
155
- export const generateColgroup = (
156
- table: PmNode,
157
- tableRef?: HTMLElement,
158
- shouldUseIncreasedScalingPercent?: boolean,
159
- isCommentEditor?: boolean,
160
- ) => {
161
- const cols: Col[] = [];
162
- const map = TableMap.get(table);
163
-
164
- // Ignored via go/ees005
165
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
166
- table.content.firstChild!.content.forEach((cell) => {
167
- const colspan = cell.attrs.colspan || 1;
168
- if (Array.isArray(cell.attrs.colwidth)) {
169
- // We slice here to guard against our colwidth array having more entries
170
- // Than the we actually span. We'll patch the document at a later point.
171
- if (tableRef) {
172
- // if we have tableRef here, isTableScalingEnabled is true
173
- let scalePercent = 1;
174
- if (isCommentEditor && !table.attrs?.width) {
175
- scalePercent = getScalingPercentForTableWithoutWidth(table, tableRef);
176
- } else {
177
- scalePercent = getTableScalingPercent(table, tableRef, shouldUseIncreasedScalingPercent);
178
- }
179
-
180
- cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
181
- // existing logic for calculating the width of the column
182
- const fixedColWidth = getColWidthFix(width, map.width);
183
- const scaledWidth = fixedColWidth * scalePercent;
184
- const finalWidth = Math.max(scaledWidth, tableCellMinWidth);
185
- cols.push([
186
- 'col',
187
- {
188
- style: `width: ${finalWidth}px;`,
189
- },
190
- ]);
191
- });
192
- } else {
193
- cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
194
- cols.push([
195
- 'col',
196
- {
197
- style: `width: ${getColWidthFix(
198
- width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth,
199
- map.width,
200
- )}px;`,
201
- },
202
- ]);
203
- });
204
- }
205
- } else {
206
- // When we have merged cells on the first row (firstChild),
207
- // We want to ensure we're creating the appropriate amount of
208
- // cols the table still has.
209
- cols.push(
210
- ...Array.from({ length: colspan }, (_) => [
211
- 'col',
212
- { style: `width: ${tableCellMinWidth}px;` },
213
- ]),
214
- );
215
- }
216
- });
217
- return cols;
218
- };
219
-
220
- export const insertColgroupFromNode = (
221
- tableRef: HTMLTableElement | null,
222
- table: PmNode,
223
- isTableScalingEnabled = false,
224
- shouldRemove = true,
225
- shouldUseIncreasedScalingPercent = false,
226
- isCommentEditor = false,
227
- ): HTMLCollection => {
228
- // Ignored via go/ees005
229
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
230
- let colgroup = tableRef?.querySelector('colgroup') as HTMLElement;
231
- if (colgroup && shouldRemove) {
232
- tableRef?.removeChild(colgroup);
233
- }
234
-
235
- colgroup = renderColgroupFromNode(
236
- table,
237
- isTableScalingEnabled ? tableRef ?? undefined : undefined,
238
- shouldUseIncreasedScalingPercent,
239
- isCommentEditor,
240
- );
241
- if (shouldRemove) {
242
- tableRef?.insertBefore(colgroup, tableRef?.firstChild);
243
- }
244
-
245
- return colgroup.children;
246
- };
247
-
248
- export const hasTableBeenResized = (table: PmNode) => {
249
- // Ignored via go/ees005
250
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
251
- return !!getFragmentBackingArray(table.content.firstChild!.content).find(
252
- (cell) => cell.attrs.colwidth,
253
- );
254
- };
255
-
256
- export const hasTableColumnBeenResized = hasTableBeenResized;
257
-
258
- /**
259
- * Check if a table has all the column width set to tableCellMinWidth(48px) or null
260
- *
261
- * @param table
262
- * @returns true if all column width is equal to tableCellMinWidth or null, false otherwise
263
- */
264
- export const isMinCellWidthTable = (table: PmNode) => {
265
- // Ignored via go/ees005
266
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
267
- const cellArray = getFragmentBackingArray(table.content.firstChild!.content);
268
- const isTableMinCellWidth = cellArray.every((cell) => {
269
- return (
270
- (cell.attrs.colwidth && cell.attrs.colwidth[0] === tableCellMinWidth) ||
271
- cell.attrs.colwidth === null
272
- );
273
- });
274
-
275
- return isTableMinCellWidth;
276
- };
277
-
278
- function renderColgroupFromNode(
279
- table: PmNode,
280
- maybeTableRef: HTMLElement | undefined,
281
- shouldUseIncreasedScalingPercent: boolean,
282
- isCommentEditor: boolean,
283
- ): HTMLElement {
284
- const rendered = DOMSerializer.renderSpec(document, [
285
- 'colgroup',
286
- {},
287
- ...generateColgroup(table, maybeTableRef, shouldUseIncreasedScalingPercent, isCommentEditor),
288
- ]);
289
-
290
- // Ignored via go/ees005
291
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
292
- return rendered.dom as HTMLElement;
293
- }
294
-
295
- export const getColgroupChildrenLength = (table: PmNode): number => {
296
- const map = TableMap.get(table);
297
- return map.width;
298
- };
299
-
300
- export const getResizerMinWidth = (node: PmNode) => {
301
- const currentColumnCount = getColgroupChildrenLength(node);
302
- const minColumnWidth = Math.min(3, currentColumnCount) * COLUMN_MIN_WIDTH;
303
- // add an extra pixel as the scale table logic will scale columns to be tableContainerWidth - 1
304
- // the table can't scale past its min-width, so instead restrict table container min width to avoid that situation
305
- return minColumnWidth + 1;
306
- };
@@ -1,120 +0,0 @@
1
- import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
- import { TableMap } from '@atlaskit/editor-tables/table-map';
5
-
6
- import { contentWidth } from './content-width';
7
- import { unitToNumber } from './unit-to-number';
8
-
9
- export interface ColumnState {
10
- index: number;
11
- width: number;
12
- minWidth: number;
13
- }
14
-
15
- // Reads `width` and `minWidth` of each column from DOM and returns `ColumnState` containing those values
16
- export const getColumnStateFromDOM = (
17
- cells: HTMLElement[],
18
- index: number,
19
- minWidth: number,
20
- ): ColumnState => {
21
- const width = calculateColumnWidth(cells, calculateColumnWidthCallback);
22
-
23
- const minColumnWidth =
24
- width < minWidth
25
- ? // for newly created column (where width < minWidth) we set minWidth = tableNewColumnMinWidth (140px atm)
26
- tableNewColumnMinWidth
27
- : calculateColumnWidth(cells, calculateColumnMinWidthCallback(minWidth));
28
-
29
- return {
30
- index,
31
- width: width < minWidth ? tableNewColumnMinWidth : width,
32
- minWidth: minColumnWidth,
33
- };
34
- };
35
-
36
- export const getFreeSpace = (state: ColumnState) => {
37
- return Math.max(state.width - state.minWidth, 0);
38
- };
39
-
40
- // Returns DOM refs of all cells in a column by `columnIndex`
41
- export const getCellsRefsInColumn = (
42
- columnIndex: number,
43
- table: PMNode,
44
- tableStart: number,
45
- domAtPos: (pos: number) => { node: Node; offset: number },
46
- ): HTMLElement[] => {
47
- const map = TableMap.get(table);
48
- const cellsPositions = map.cellsInRect({
49
- left: columnIndex,
50
- right: columnIndex + 1,
51
- top: 0,
52
- bottom: map.height,
53
- });
54
- const cells: HTMLElement[] = [];
55
- cellsPositions.forEach((pos) => {
56
- // Ignored via go/ees005
57
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
58
- const col = findDomRefAtPos(pos + tableStart, domAtPos) as HTMLElement;
59
- if (col) {
60
- cells.push(col);
61
- }
62
- });
63
- return cells;
64
- };
65
-
66
- // calculates column widths based on `cells` DOM refs
67
- export const calculateColumnWidth = (
68
- cells: HTMLElement[],
69
- calculateColumnWidthCb: (
70
- css: CSSStyleDeclaration,
71
- cellRef: HTMLElement,
72
- colSpan: number,
73
- ) => number,
74
- ): number => {
75
- let maxColWidth = 0;
76
- let colSpanWidth = 0;
77
-
78
- cells.forEach((cellRef) => {
79
- const css = getComputedStyle(cellRef);
80
- const colspan = Number(cellRef.getAttribute('colspan') || 1);
81
-
82
- if (colspan > 1) {
83
- colSpanWidth = calculateColumnWidthCb(css, cellRef, colspan);
84
- return;
85
- }
86
-
87
- if (css) {
88
- const colWidth = calculateColumnWidthCb(css, cellRef, colspan);
89
- maxColWidth = Math.max(colWidth, maxColWidth);
90
- }
91
- });
92
-
93
- return maxColWidth || colSpanWidth;
94
- };
95
-
96
- export const addContainerLeftRightPadding = (amount: number, css: CSSStyleDeclaration): number =>
97
- amount + unitToNumber(css.paddingLeft) + unitToNumber(css.paddingRight);
98
-
99
- function calculateColumnWidthCallback(css: CSSStyleDeclaration): number {
100
- return unitToNumber(css.width);
101
- }
102
-
103
- function calculateColumnMinWidthCallback(
104
- minColumnWidth: number,
105
- ): (css: CSSStyleDeclaration, cellRef: HTMLElement, colSpan: number) => number {
106
- return (css, cellRef, colSpan) => {
107
- if (colSpan && colSpan > 1) {
108
- return unitToNumber(css.width);
109
- }
110
-
111
- const { minWidth: minContentWidth } = contentWidth(cellRef, cellRef);
112
- // Override the min width, if there is content that can't collapse
113
- // Past a certain width.
114
- return Math.max(
115
- addContainerLeftRightPadding(minContentWidth, css),
116
- minContentWidth,
117
- minColumnWidth,
118
- );
119
- };
120
- }
@@ -1,11 +0,0 @@
1
- export const COLUMN_MIN_WIDTH = 48;
2
- export const TABLE_MAX_WIDTH = 1800;
3
- export const FULL_WIDTH_EDITOR_CONTENT_WIDTH = 1800;
4
- export const MAX_SCALING_PERCENT = 0.3;
5
- export const MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION = 0.4;
6
- // Used to calculate the width of a table using the Editor width
7
- export const TABLE_EDITOR_MARGIN = 76;
8
- const COMMENT_AK_EDITOR_CONTENT_AREA_PADDING = 20;
9
- const COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN = 12;
10
- export const TABLE_OFFSET_IN_COMMENT_EDITOR =
11
- 2 * (COMMENT_AK_EDITOR_CONTENT_AREA_PADDING + COMMENT_PM_TABLE_RESIZING_PLUGIN_MARGIN);
@@ -1,118 +0,0 @@
1
- import { unitToNumber } from './unit-to-number';
2
-
3
- // calculates content width of a cell
4
- export function contentWidth(
5
- elem: HTMLElement,
6
- container: HTMLElement,
7
- colWidths: number[] = [],
8
- canvas: HTMLCanvasElement = document.createElement('canvas'),
9
- ): { minWidth: number; width: number } {
10
- return calcContentWidth(elem, container || elem, canvas, colWidths);
11
- }
12
-
13
- function calcContentWidth(
14
- elem: HTMLElement,
15
- container: HTMLElement,
16
- canvas: HTMLCanvasElement,
17
- colWidths: number[],
18
- ): { minWidth: number; width: number } {
19
- const flowWidths = [] as number[];
20
- let curWidth = 0;
21
-
22
- for (let i = 0; i < elem.childNodes.length; i++) {
23
- // Ignored via go/ees005
24
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
25
- const child = elem.childNodes[i] as HTMLElement;
26
-
27
- if (child.nodeType === Node.COMMENT_NODE) {
28
- continue;
29
- }
30
-
31
- if (child.nodeType === Node.TEXT_NODE) {
32
- // Ignored via go/ees005
33
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
34
- const parent = child.parentNode as HTMLElement;
35
- const parentStyle = getComputedStyle(parent);
36
- let contentLength = 0;
37
-
38
- if (parent.nodeName === 'CODE' || parent.nodeName === 'PRE') {
39
- contentLength = handlePreText(canvas, parent, child.textContent, parentStyle.font);
40
- } else {
41
- contentLength = measureText(canvas, child.textContent, parentStyle.font);
42
- }
43
-
44
- const left = parent.offsetLeft - container.offsetLeft;
45
- flowWidths.push(curWidth);
46
-
47
- curWidth += contentLength + left;
48
-
49
- // If the text isn't meant to wrap, we should set that as a hard limit.
50
- if (parentStyle.whiteSpace === 'nowrap') {
51
- // + 3 is for date offset plus cursor
52
- // TODO: ED-26961 - There should be a programmatic way to get this.
53
- colWidths.push(parent.offsetWidth + 3);
54
- }
55
- } else {
56
- // TODO: ED-26961 - doesn't quite work right with spacing
57
- const style = getComputedStyle(child);
58
-
59
- if (style.minWidth && style.minWidth.endsWith('px') && style.minWidth !== '0px') {
60
- colWidths.push(unitToNumber(style.minWidth));
61
- }
62
-
63
- const { width } = contentWidth(child, container, colWidths, canvas);
64
- if (style.display && style.display.indexOf('inline') > -1) {
65
- // is inline element, add to curWidth
66
- curWidth += width;
67
- } else {
68
- // block element, reset curWidth
69
- flowWidths.push(curWidth);
70
- curWidth = width;
71
- }
72
- }
73
- }
74
-
75
- flowWidths.push(curWidth);
76
-
77
- return {
78
- minWidth: colWidths.reduce((oldMax, width) => Math.max(width, oldMax), 0),
79
- width: flowWidths.reduce((oldMax, width) => Math.max(width, oldMax), 0),
80
- };
81
- }
82
-
83
- function measureText(canvas: HTMLCanvasElement, text: string | null, font: string | null): number {
84
- const ctx = canvas.getContext('2d');
85
- if (!ctx) {
86
- return 0;
87
- }
88
- if (font) {
89
- ctx.font = font;
90
- }
91
- return Math.round(ctx.measureText(text || '').width);
92
- }
93
-
94
- function handlePreText(
95
- canvas: HTMLCanvasElement,
96
- node: HTMLElement,
97
- textContent: string | null,
98
- font: string | null,
99
- ): number {
100
- let parent = node;
101
- if (node.nodeName === 'CODE') {
102
- // Ignored via go/ees005
103
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @atlaskit/editor/no-as-casting
104
- parent = node.parentNode! as HTMLElement;
105
- }
106
-
107
- // Ignored via go/ees005
108
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
109
- const computedStyle = getComputedStyle(parent!);
110
- if (textContent && computedStyle.whiteSpace === 'pre') {
111
- // If white space is pre grab the longest line in the block.
112
- return textContent
113
- .split('\n')
114
- .reduce((acc, current) => Math.max(measureText(canvas, current, font), acc), 0);
115
- }
116
-
117
- return measureText(canvas, textContent, font);
118
- }
@@ -1,132 +0,0 @@
1
- import { tableCellBorderWidth, tableMarginTop } from '@atlaskit/editor-common/styles';
2
- import { closestElement, containsClassName, parsePx } from '@atlaskit/editor-common/utils';
3
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
-
6
- import { TableCssClassName as ClassName } from '../../../types';
7
- import { getPluginState as getMainPluginState } from '../../plugin-factory';
8
- import { colWidthsForRow } from '../../utils/column-controls';
9
- import { getRowHeights } from '../../utils/row-controls';
10
-
11
- export const updateControls = () => (state: EditorState) => {
12
- const { tableRef } = getMainPluginState(state);
13
- if (!tableRef) {
14
- return;
15
- }
16
- const tr = tableRef.querySelector('tr');
17
- if (!tr) {
18
- return;
19
- }
20
- const wrapper = tableRef.parentElement;
21
- if (!(wrapper && wrapper.parentElement)) {
22
- return;
23
- }
24
-
25
- const rowControls = wrapper.parentElement.querySelectorAll<HTMLElement>(
26
- `.${ClassName.ROW_CONTROLS_BUTTON_WRAP}`,
27
- );
28
- const numberedRows = wrapper.parentElement.querySelectorAll<HTMLElement>(
29
- ClassName.NUMBERED_COLUMN_BUTTON,
30
- );
31
-
32
- syncStickyRowToTable(tableRef);
33
-
34
- const rowHeights = getRowHeights(tableRef);
35
-
36
- // update rows controls height on resize
37
- for (let i = 0, count = rowControls.length; i < count; i++) {
38
- const height = rowHeights[i];
39
- if (height) {
40
- rowControls[i].style.height = `${height}px`;
41
-
42
- if (numberedRows.length) {
43
- numberedRows[i].style.height = `${height}px`;
44
- }
45
- }
46
- }
47
- };
48
-
49
- export const isClickNear = (event: MouseEvent, click: { x: number; y: number }): boolean => {
50
- const dx = click.x - event.clientX,
51
- dy = click.y - event.clientY;
52
- return dx * dx + dy * dy < 100;
53
- };
54
-
55
- export const getResizeCellPos = (view: EditorView, event: MouseEvent): number | null => {
56
- // Ignored via go/ees005
57
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
58
- const target = event.target as HTMLElement;
59
-
60
- if (!containsClassName(target, ClassName.RESIZE_HANDLE_DECORATION)) {
61
- return null;
62
- }
63
-
64
- const tableCell = closestElement(target, 'td, th');
65
-
66
- if (!tableCell) {
67
- return null;
68
- }
69
-
70
- const cellStartPosition = view.posAtDOM(tableCell, 0);
71
- return cellStartPosition - 1;
72
- };
73
-
74
- export const updateStickyMargins = (table: HTMLElement) => {
75
- const row = table.querySelector('tr.sticky');
76
- if (!row) {
77
- table.style.marginTop = '';
78
- return;
79
- }
80
-
81
- const paddingTop = parsePx(window.getComputedStyle(row).paddingTop || '') || 0;
82
-
83
- const firstRowHeight = row.getBoundingClientRect().height - paddingTop - tableCellBorderWidth;
84
-
85
- table.style.marginTop = `${tableMarginTop + firstRowHeight}px`;
86
- };
87
-
88
- const applyColWidthsToStickyRow = (
89
- // @ts-ignore - CCFE error TS6133: 'colGroup' is declared but its value is never read.
90
- colGroup: HTMLTableColElement | null,
91
- headerRow: HTMLTableRowElement,
92
- ) => {
93
- // sync column widths for the sticky row
94
- const newCols = colWidthsForRow(headerRow);
95
-
96
- if (newCols) {
97
- headerRow.style.gridTemplateColumns = newCols;
98
- }
99
- };
100
-
101
- export const syncStickyRowToTable = (tableRef?: HTMLElement | null) => {
102
- if (!tableRef) {
103
- return;
104
- }
105
-
106
- const headerRow = tableRef.querySelector('tr[data-header-row]') as HTMLTableRowElement;
107
-
108
- if (!headerRow) {
109
- return;
110
- }
111
- applyColWidthsToStickyRow(tableRef.querySelector('colgroup'), headerRow);
112
- applyTableWidthToStickyRow(tableRef, headerRow);
113
- };
114
-
115
- const applyTableWidthToStickyRow = (tableRef: HTMLElement, headerRow: HTMLTableRowElement) => {
116
- // Ignored via go/ees005
117
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
- const tbody = tableRef.querySelector('tbody')!;
119
- const wrapper = tableRef.parentElement;
120
-
121
- if (tbody && wrapper) {
122
- // when resizing in Chrome, clientWidth will give us 759px
123
- // but toggling the sticky class will reset it to 760px.
124
- //
125
- // both elements in the dom + inspector will
126
- // be the same width but at layout will be different..
127
- const newWidth = Math.min(tbody.offsetWidth + 1, wrapper.offsetWidth);
128
-
129
- headerRow.style.width = `${newWidth}px`;
130
- headerRow.scrollLeft = wrapper.scrollLeft;
131
- }
132
- };