@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,282 +0,0 @@
1
- import type { CellAttributes } from '@atlaskit/adf-schema';
2
- import {
3
- getParentNodeWidth,
4
- getTableContainerWidth,
5
- layoutToWidth,
6
- } from '@atlaskit/editor-common/node-width';
7
- import { calcTableWidth } from '@atlaskit/editor-common/styles';
8
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
9
- import { calcTableColumnWidths } from '@atlaskit/editor-common/utils';
10
- import type { NodeSpec, Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
11
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
12
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
13
- import {
14
- akEditorFullWidthLayoutWidth,
15
- akEditorGutterPaddingDynamic,
16
- akEditorTableNumberColumnWidth,
17
- akEditorGutterPaddingReduced,
18
- akEditorFullPageNarrowBreakout,
19
- } from '@atlaskit/editor-shared-styles';
20
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
21
-
22
- import type { TableOptions } from '../../../nodeviews/types';
23
-
24
- import { hasTableBeenResized, hasTableColumnBeenResized } from './colgroup';
25
- import {
26
- MAX_SCALING_PERCENT,
27
- MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION,
28
- TABLE_MAX_WIDTH,
29
- } from './consts';
30
-
31
- // Translates named layouts in number values.
32
- export function getLayoutSize(
33
- tableLayout: 'default' | 'wide' | 'full-width',
34
- containerWidth: number = 0,
35
- options: TableOptions,
36
- ): number {
37
- const { isFullWidthModeEnabled } = options;
38
-
39
- if (isFullWidthModeEnabled) {
40
- let padding: number = akEditorGutterPaddingDynamic();
41
- if (
42
- containerWidth <= akEditorFullPageNarrowBreakout &&
43
- expValEquals('platform_editor_preview_panel_responsiveness', 'isEnabled', true)
44
- ) {
45
- padding = akEditorGutterPaddingReduced;
46
- }
47
-
48
- return containerWidth
49
- ? Math.min(containerWidth - padding * 2, akEditorFullWidthLayoutWidth)
50
- : akEditorFullWidthLayoutWidth;
51
- }
52
-
53
- const calculatedTableWidth = calcTableWidth(tableLayout, containerWidth, true);
54
- if (calculatedTableWidth !== 'inherit') {
55
- return calculatedTableWidth;
56
- }
57
-
58
- return layoutToWidth[tableLayout] || containerWidth;
59
- }
60
-
61
- // Does the current position point at a cell.
62
- export function pointsAtCell($pos: ResolvedPos) {
63
- return (
64
- ($pos.parent.type.spec as NodeSpec & { tableRole: string }).tableRole === 'row' &&
65
- $pos.nodeAfter
66
- );
67
- }
68
-
69
- // Get the current col width, handles colspan.
70
- export function currentColWidth(
71
- view: EditorView,
72
- cellPos: number,
73
- { colspan, colwidth }: CellAttributes,
74
- ): number {
75
- const width = colwidth && colwidth[colwidth.length - 1];
76
- if (width) {
77
- return width;
78
- }
79
- // Not fixed, read current width from DOM
80
- // Ignored via go/ees005
81
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
82
- let domWidth = (view.domAtPos(cellPos + 1).node as HTMLElement).offsetWidth;
83
- let parts = colspan || 0;
84
- if (colwidth) {
85
- for (let i = 0; i < (colspan || 0); i++) {
86
- if (colwidth[i]) {
87
- domWidth -= colwidth[i];
88
- parts--;
89
- }
90
- }
91
- }
92
-
93
- return domWidth / parts;
94
- }
95
-
96
- interface getTableMaxWidthProps {
97
- table: PMNode;
98
- tableStart: number;
99
- state: EditorState;
100
- layout: 'default' | 'wide' | 'full-width';
101
- getEditorContainerWidth: GetEditorContainerWidth;
102
- }
103
-
104
- export const getTableMaxWidth = ({
105
- table,
106
- tableStart,
107
- state,
108
- layout,
109
- getEditorContainerWidth,
110
- }: getTableMaxWidthProps) => {
111
- const containerWidth = getEditorContainerWidth();
112
- const parentWidth = getParentNodeWidth(tableStart, state, containerWidth);
113
-
114
- let maxWidth =
115
- parentWidth || table.attrs.width || getLayoutSize(layout, containerWidth.width, {});
116
-
117
- if (table.attrs.isNumberColumnEnabled) {
118
- maxWidth -= akEditorTableNumberColumnWidth;
119
- }
120
-
121
- return maxWidth as number;
122
- };
123
-
124
- /**
125
- *
126
- * @param table
127
- * @returns calculated width of <table /> element derived from sum of colwidths on tableCell or tableHeader nodes or falls back to container width
128
- */
129
- export const getTableElementWidth = (table: PMNode) => {
130
- if (hasTableBeenResized(table)) {
131
- // TODO: ED-26961 - is there a scenario where ADF columns are SMALLER than container width?
132
- return calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
133
- }
134
-
135
- return getTableContainerElementWidth(table);
136
- };
137
-
138
- export const getTableContainerElementWidth = (table: PMNode) => {
139
- return getTableContainerWidth(table);
140
- };
141
-
142
- // eslint-disable-next-line jsdoc/require-example
143
- /**
144
- * This function is used to set the max width for table resizer container.
145
- * @param isCommentEditor Whether the editor is in comment mode.
146
- * @param isChromelessEditor Whether the editor is chromeless.
147
- * @param isTableScalingEnabled Whether table scaling is enabled.
148
- * @returns The CSS max-width value
149
- */
150
- export const getTableResizerContainerMaxWidthInCSS = (
151
- isCommentEditor?: boolean,
152
- isChromelessEditor?: boolean,
153
- isTableScalingEnabled?: boolean,
154
- ): string => {
155
- const maxResizerWidthForNonCommentEditor = isTableScalingEnabled
156
- ? `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ${TABLE_MAX_WIDTH}px)`
157
- : `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2) - var(--ak-editor--resizer-handle-spacing)), ${TABLE_MAX_WIDTH}px)`;
158
- return isCommentEditor || isChromelessEditor ? '100%' : maxResizerWidthForNonCommentEditor;
159
- };
160
-
161
- // eslint-disable-next-line jsdoc/require-example
162
- /**
163
- * This function is used in NodeView for TableResizer to set the max width for table resizer container
164
- * @param node The ProseMirror node representing the table.
165
- * @param isCommentEditor Whether the editor is in comment mode.
166
- * @param isChromelessEditor Whether the editor is chromeless.
167
- * @returns The CSS max-width value for the table resizer container.
168
- */
169
- export const getTableResizerItemWidth = (
170
- node: PMNode,
171
- isCommentEditor?: boolean,
172
- isChromelessEditor?: boolean,
173
- ): number | undefined => {
174
- const tableWidthAttribute = getTableContainerWidth(node);
175
- if (!node.attrs.width && (isCommentEditor || isChromelessEditor)) {
176
- // width undefined would make .resizer-item width to be `auto`
177
- return undefined;
178
- }
179
- return tableWidthAttribute;
180
- };
181
-
182
- // eslint-disable-next-line jsdoc/require-example
183
- /**
184
- * This function is used to set the CSS width value for the table resizer-item.
185
- * Because comment and chromeless editors don't have container-type: inline-size set,
186
- * we need to calculate the width based on the table node width.
187
- * If the table node width is not set, it will return 'auto'.
188
- * This is used in table toDOM
189
- * @param node The ProseMirror node representing the table.
190
- * @param isCommentEditor Whether the editor is in comment mode.
191
- * @param isChromelessEditor Whether the editor is chromeless.
192
- * @returns The CSS width value for the table container.
193
- */
194
- export const getTableResizerItemWidthInCSS = (
195
- node: PMNode,
196
- isCommentEditor?: boolean,
197
- isChromelessEditor?: boolean,
198
- ): string => {
199
- const tableWidthAttribute = getTableResizerItemWidth(node, isCommentEditor, isChromelessEditor);
200
- return tableWidthAttribute ? `${tableWidthAttribute}px` : 'auto';
201
- };
202
-
203
- // eslint-disable-next-line jsdoc/require-example
204
- /**
205
- * This function is used to set the table width --ak-editor-table-width CSS property for full page editor.
206
- * Which is applied to the table resizer container.
207
- * For Full page appearance, we don't need to use containerWidth from JS, as we can use cqw value.
208
- * So we set dynamic containerWidth from JS to CSS property.
209
- * @param node The ProseMirror node representing the table.
210
- * @param isCommentEditor Whether the editor is in comment mode.
211
- * @param isChromelessEditor Whether the editor is chromeless.
212
- * @param isTableScalingEnabled Whether table scaling is enabled.
213
- * @param tableWidthFromJS The width of the container element. In toDOM it'd be undefined, but will have a value from nodeView.
214
- * @returns The CSS width value for the table.
215
- */
216
- export const getTableResizerContainerForFullPageWidthInCSS = (
217
- node: PMNode,
218
- isTableScalingEnabled?: boolean,
219
- ): string => {
220
- const tableWidth = getTableContainerElementWidth(node);
221
- // for full page appearance
222
- if (isTableScalingEnabled) {
223
- return `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2)), ${tableWidth}px)`;
224
- }
225
- return `min(calc(100cqw - calc(var(--ak-editor--large-gutter-padding) * 2) - var(--ak-editor--resizer-handle-spacing)), ${tableWidth}px)`;
226
- };
227
-
228
- export const getTableScalingPercent = (
229
- table: PMNode,
230
- tableRef: HTMLElement | null,
231
- shouldUseIncreasedScalingPercent?: boolean,
232
- ) => {
233
- const maxScalingPercent = shouldUseIncreasedScalingPercent
234
- ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
235
- : MAX_SCALING_PERCENT;
236
-
237
- const tableWidth = getTableContainerElementWidth(table);
238
- const renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
239
- // minus 1 here to avoid any 1px scroll in Firefox
240
- let scalePercent = (renderWidth - 1) / tableWidth;
241
- scalePercent = Math.max(scalePercent, 1 - maxScalingPercent);
242
-
243
- return Math.min(scalePercent, 1);
244
- };
245
-
246
- // This function is used to default and full-width tables in Comment/Chromeless editors
247
- // These tables don't have node.attrs.width set. Their pm-table-wrapper width depend on the editor container width.
248
- // actual table node width can be calculated as sum of colwidth values if table's columns were resized.
249
- // If colwidth are not set, table columns are not resized, they all are equal widths.
250
- export const getScalingPercentForTableWithoutWidth = (
251
- table: PMNode,
252
- tableRef: HTMLElement | null,
253
- ) => {
254
- // are table columns resized
255
- if (hasTableColumnBeenResized(table)) {
256
- const tableWidth = calcTableColumnWidths(table).reduce((sum, width) => sum + width, 0);
257
- const renderWidth = tableRef?.parentElement?.clientWidth || tableWidth;
258
-
259
- // minus 1 here to avoid any 1px scroll in Firefox
260
- return (renderWidth - 1) / tableWidth;
261
- }
262
-
263
- // When table cols are not resized and table width is not set,
264
- // tableWidth is equal to renderWidth
265
- return 1;
266
- };
267
-
268
- export const getStaticTableScalingPercent = (
269
- table: PMNode,
270
- tableRenderWidth: number,
271
- shouldUseIncreasedScalingPercent?: boolean,
272
- ) => {
273
- const maxScalingPercent = shouldUseIncreasedScalingPercent
274
- ? MAX_SCALING_PERCENT_TABLES_WITH_FIXED_COLUMN_WIDTHS_OPTION
275
- : MAX_SCALING_PERCENT;
276
-
277
- const tableWidth = getTableContainerElementWidth(table);
278
- // minus 1 here to avoid any 1px scroll in Firefox
279
- let scalePercent = (tableRenderWidth - 1) / tableWidth;
280
- scalePercent = Math.max(scalePercent, 1 - maxScalingPercent);
281
- return Math.min(scalePercent, 1);
282
- };
@@ -1,34 +0,0 @@
1
- // Resize a given column by an amount from the current state
2
- import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
3
-
4
- import { growColumn, shrinkColumn } from './resize-logic';
5
- import { updateColgroup } from './resize-state';
6
- import type { ResizeState } from './types';
7
-
8
- export const resizeColumn = (
9
- resizeState: ResizeState,
10
- colIndex: number,
11
- amount: number,
12
- tableRef: HTMLElement | null,
13
- tableNode: PmNode,
14
- selectedColumns?: number[],
15
- isTableScalingEnabled = false,
16
- scalePercent = 1,
17
- ): ResizeState => {
18
- let resizeAmount = amount;
19
-
20
- if (isTableScalingEnabled) {
21
- resizeAmount = amount / scalePercent;
22
- }
23
-
24
- const newState =
25
- resizeAmount > 0
26
- ? growColumn(resizeState, colIndex, resizeAmount, selectedColumns)
27
- : resizeAmount < 0
28
- ? shrinkColumn(resizeState, colIndex, resizeAmount, selectedColumns)
29
- : resizeState;
30
-
31
- updateColgroup(newState, tableRef, tableNode, isTableScalingEnabled, scalePercent);
32
-
33
- return newState;
34
- };
@@ -1,289 +0,0 @@
1
- import type { ColumnState } from './column-state';
2
- import { getFreeSpace } from './column-state';
3
- import { bulkColumnsResize, getTotalWidth } from './resize-state';
4
- import type { ResizeState } from './types';
5
-
6
- export const growColumn = (
7
- state: ResizeState,
8
- colIndex: number,
9
- amount: number,
10
- selectedColumns?: number[],
11
- ): ResizeState => {
12
- // can't grow if columns don't exist or it's the last column
13
- if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
14
- return state;
15
- }
16
- const res = moveSpaceFrom(state, colIndex + 1, colIndex, amount);
17
- const remaining = amount - res.amount;
18
- let newState = res.state;
19
-
20
- if (remaining > 0) {
21
- newState = stackSpace(newState, colIndex, remaining).state;
22
- }
23
- if (selectedColumns && selectedColumns.length > 1) {
24
- return bulkColumnsResize(newState, selectedColumns, colIndex);
25
- }
26
-
27
- return newState;
28
- };
29
-
30
- export const shrinkColumn = (
31
- state: ResizeState,
32
- colIndex: number,
33
- amount: number,
34
- selectedColumns?: number[],
35
- ): ResizeState => {
36
- // can't shrink if columns don't exist
37
- if (!state.cols[colIndex]) {
38
- return state;
39
- }
40
- // try to shrink dragging column by giving from the column to the right first
41
- const res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
42
- let newState = res.state;
43
-
44
- const isOverflownTable = getTotalWidth(newState) > newState.maxSize;
45
- const isLastColumn = !newState.cols[colIndex + 1];
46
- // stop resizing the last column once table is not overflown
47
- if (isLastColumn && !isOverflownTable) {
48
- return newState;
49
- }
50
-
51
- const remaining = amount + res.amount;
52
- if (remaining < 0) {
53
- newState = stackSpace(newState, colIndex + 1, remaining).state;
54
- }
55
- if (selectedColumns && selectedColumns.length > 1) {
56
- return bulkColumnsResize(newState, selectedColumns, colIndex);
57
- }
58
-
59
- return newState;
60
- };
61
-
62
- export function reduceSpace(
63
- state: ResizeState,
64
- amount: number,
65
- ignoreCols: number[] = [],
66
- ): ResizeState {
67
- let remaining = amount;
68
-
69
- // keep trying to resolve resize request until we run out of free space,
70
- // or nothing to resize
71
- while (remaining > 0) {
72
- // filter candidates only with free space
73
- const candidates = state.cols.filter((column) => {
74
- return getFreeSpace(column) && ignoreCols.indexOf(column.index) === -1;
75
- });
76
- if (candidates.length === 0) {
77
- break;
78
- }
79
- const requestedResize = Math.floor(remaining / candidates.length);
80
- if (requestedResize === 0) {
81
- break;
82
- }
83
-
84
- candidates.forEach((candidate) => {
85
- let newWidth = candidate.width - requestedResize;
86
- if (newWidth < candidate.minWidth) {
87
- // If the new requested width is less than our min
88
- // Calc what width we didn't use, we'll try extract that
89
- // from other cols.
90
- const remainder = candidate.minWidth - newWidth;
91
- newWidth = candidate.minWidth;
92
- remaining = remaining - requestedResize + remainder;
93
- } else {
94
- remaining -= requestedResize;
95
- }
96
-
97
- state = {
98
- ...state,
99
- cols: [
100
- ...state.cols.slice(0, candidate.index),
101
- { ...candidate, width: newWidth },
102
- ...state.cols.slice(candidate.index + 1),
103
- ],
104
- };
105
- });
106
- }
107
-
108
- return state;
109
- }
110
-
111
- enum ColType {
112
- SOURCE = 'src',
113
- DEST = 'dest',
114
- }
115
-
116
- // TODO: ED-26961 - should handle when destIdx:
117
- // - is beyond the range, and then not give it back
118
- function moveSpaceFrom(
119
- state: ResizeState,
120
- srcIdx: number,
121
- destIdx: number,
122
- amount: number,
123
- useFreeSpace: boolean = true,
124
- ): { state: ResizeState; amount: number } {
125
- const srcCol = state.cols[srcIdx];
126
- const destCol = state.cols[destIdx];
127
-
128
- if (useFreeSpace) {
129
- const freeSpace = getFreeSpace(srcCol);
130
- // if taking more than source column's free space, only take that much
131
- if (amountFor(ColType.DEST)(amount) > freeSpace) {
132
- amount = amount > 0 ? freeSpace : -freeSpace;
133
- }
134
- }
135
-
136
- // if the source column shrinks past its min size, don't give the space away
137
- if (
138
- amountFor(ColType.SOURCE)(amount) < 0 &&
139
- widthFor(ColType.SOURCE)(amount, srcCol, destCol) < srcCol.minWidth
140
- ) {
141
- amount = srcCol.width - srcCol.minWidth;
142
- }
143
-
144
- const newDest = destCol
145
- ? { ...destCol, width: widthFor(ColType.DEST)(amount, srcCol, destCol) }
146
- : undefined;
147
- if (!newDest && amountFor(ColType.SOURCE)(amount) < 0) {
148
- // non-zero-sum game, ensure that we're not removing more than the total table width either
149
- const totalWidth = getTotalWidth(state);
150
- if (
151
- totalWidth - srcCol.width + widthFor(ColType.SOURCE)(amount, srcCol, destCol) <
152
- state.maxSize
153
- ) {
154
- // would shrink table below max width, stop it
155
- amount = state.maxSize - (totalWidth - srcCol.width) - srcCol.width - 1;
156
- }
157
- }
158
-
159
- const newSrc = {
160
- ...srcCol,
161
- width: widthFor(ColType.SOURCE)(amount, srcCol, destCol),
162
- };
163
-
164
- const newCols = state.cols
165
- .map((existingCol, idx) => (idx === srcIdx ? newSrc : idx === destIdx ? newDest : existingCol))
166
- .filter(Boolean) as ColumnState[];
167
-
168
- return { state: { ...state, cols: newCols }, amount };
169
- }
170
-
171
- function stackSpace(
172
- state: ResizeState,
173
- destIdx: number,
174
- amount: number,
175
- ): { state: ResizeState; remaining: number } {
176
- let candidates = getCandidates(state, destIdx, amount);
177
-
178
- while (candidates.length && amount) {
179
- // search for most (or least) free space in candidates
180
- const candidateIdx = findNextFreeColumn(candidates, amount);
181
- if (candidateIdx === -1) {
182
- // stack to the right -> growing the dragging column and go overflow
183
- if (amount > 0) {
184
- return {
185
- state: {
186
- ...state,
187
- cols: [
188
- ...state.cols.slice(0, destIdx),
189
- {
190
- ...state.cols[destIdx],
191
- width: state.cols[destIdx].width + amount,
192
- },
193
- ...state.cols.slice(destIdx + 1),
194
- ],
195
- },
196
- remaining: amount,
197
- };
198
- }
199
-
200
- // stacking to the left, if no free space remains
201
- break;
202
- }
203
-
204
- const column = candidates.find((col) => col.index === candidateIdx);
205
- if (!column || getFreeSpace(column) <= 0) {
206
- // no more columns with free space remain
207
- break;
208
- }
209
-
210
- const res = moveSpaceFrom(state, column.index, destIdx, amount);
211
- state = res.state;
212
- amount -= res.amount;
213
-
214
- candidates = candidates.filter((col) => col.index !== candidateIdx);
215
- }
216
-
217
- return {
218
- state,
219
- remaining: amount,
220
- };
221
- }
222
-
223
- function findNextFreeColumn(columns: ColumnState[], amount: number): number {
224
- if (columns.length === 0) {
225
- return -1;
226
- }
227
- const direction = amount < 0 ? 'left' : 'right';
228
- if (direction === 'left') {
229
- columns = columns.slice().reverse();
230
- }
231
-
232
- let freeIndex = -1;
233
- columns.forEach((column) => {
234
- if (getFreeSpace(column) && freeIndex === -1) {
235
- freeIndex = column.index;
236
- }
237
- });
238
-
239
- if (freeIndex === -1) {
240
- return -1;
241
- }
242
-
243
- return freeIndex;
244
- }
245
-
246
- function amountFor(colType: ColType): (amount: number) => number {
247
- return (amount) =>
248
- colType === ColType.SOURCE ? (amount > 0 ? -amount : amount) : amount < 0 ? -amount : amount;
249
- }
250
-
251
- function widthFor(
252
- colType: ColType,
253
- ): (amount: number, srcCol: ColumnState, destCol: ColumnState) => number {
254
- return (amount, srcCol, destCol) =>
255
- (colType === ColType.SOURCE ? srcCol : destCol).width + amountFor(colType)(amount);
256
- }
257
-
258
- function getCandidates(state: ResizeState, destIdx: number, amount: number): ColumnState[] {
259
- const candidates = state.cols;
260
-
261
- // only consider rows after the selected column in the direction of resize
262
- return amount < 0 ? candidates.slice(0, destIdx) : candidates.slice(destIdx + 1);
263
- }
264
-
265
- /**
266
- * Update the given column based on resizeAmount, maintaining all other columns
267
- */
268
- export function updateAffectedColumn(
269
- resizeState: ResizeState,
270
- colIndex: number,
271
- resizeAmount: number,
272
- ): ResizeState {
273
- const updatedCols = resizeState.cols.map((col, index) => {
274
- if (index === colIndex) {
275
- const newWidth = Math.max(col.width + resizeAmount, col.minWidth);
276
- return {
277
- ...col,
278
- width: newWidth,
279
- };
280
- }
281
- return col;
282
- });
283
-
284
- return {
285
- ...resizeState,
286
- tableWidth: updatedCols.reduce((acc, col) => acc + col.width, 0),
287
- cols: updatedCols,
288
- };
289
- }