@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,136 +0,0 @@
1
- import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
2
- import { isVerticalPosition } from '@atlaskit/editor-common/guideline';
3
- import {
4
- akEditorCalculatedWideLayoutWidth,
5
- akEditorDefaultLayoutWidth,
6
- akEditorFullWidthLayoutWidth,
7
- akEditorGutterPaddingDynamic,
8
- akEditorGutterPaddingReduced,
9
- akEditorFullPageNarrowBreakout,
10
- } from '@atlaskit/editor-shared-styles';
11
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
-
13
- const numberOfLanesInDefaultLayoutWidth = 12;
14
-
15
- const calculateSubSnappingWidths = (totalLanes: number, totalWidth: number) =>
16
- new Array(Math.round(totalLanes / 2) - 1)
17
- .fill(totalWidth / totalLanes)
18
- .map((v, i) => v * (i + 1) * 2);
19
-
20
- export const calculateDefaultSnappings = (lengthOffset: number = 0) => [
21
- ...calculateSubSnappingWidths(
22
- numberOfLanesInDefaultLayoutWidth,
23
- akEditorDefaultLayoutWidth + lengthOffset,
24
- ),
25
- akEditorDefaultLayoutWidth + lengthOffset,
26
- akEditorCalculatedWideLayoutWidth + lengthOffset,
27
- akEditorFullWidthLayoutWidth + lengthOffset,
28
- ];
29
-
30
- export type GuidelineExcludeConfig = {
31
- innerGuidelines: boolean;
32
- breakoutPoints: boolean;
33
- };
34
-
35
- const getPadding = (editorContainerWith: number) => {
36
- return editorContainerWith <= akEditorFullPageNarrowBreakout &&
37
- expValEquals('platform_editor_preview_panel_responsiveness', 'isEnabled', true)
38
- ? akEditorGutterPaddingReduced
39
- : akEditorGutterPaddingDynamic();
40
- };
41
-
42
- // FF TablePreserve for calculateDefaultSnappings
43
- export const calculateDefaultTablePreserveSnappings = (
44
- lengthOffset = 0,
45
- editorContainerWith = akEditorFullWidthLayoutWidth,
46
- exclude: GuidelineExcludeConfig = {
47
- innerGuidelines: false,
48
- breakoutPoints: false,
49
- },
50
- ) => {
51
- const padding = getPadding(editorContainerWith);
52
- const dynamicFullWidthLine =
53
- editorContainerWith - padding * 2 >= akEditorFullWidthLayoutWidth
54
- ? akEditorFullWidthLayoutWidth
55
- : editorContainerWith - padding * 2;
56
-
57
- const guides = [dynamicFullWidthLine - lengthOffset];
58
-
59
- if (!exclude.breakoutPoints) {
60
- guides.unshift(
61
- akEditorDefaultLayoutWidth + lengthOffset,
62
- akEditorCalculatedWideLayoutWidth + lengthOffset,
63
- );
64
- }
65
-
66
- if (!exclude.innerGuidelines) {
67
- guides.unshift(
68
- 0,
69
- ...calculateSubSnappingWidths(
70
- numberOfLanesInDefaultLayoutWidth,
71
- akEditorDefaultLayoutWidth + lengthOffset,
72
- ),
73
- );
74
- }
75
-
76
- return guides;
77
- };
78
-
79
- export const defaultSnappingWidths = calculateDefaultSnappings();
80
-
81
- export const PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET = 0;
82
- // FF TablePreserve for defaultSnappingWidths
83
- export const defaultTablePreserveSnappingWidths = (
84
- lengthOffset: number,
85
- editorContainerWidth: number,
86
- exclude: GuidelineExcludeConfig = {
87
- innerGuidelines: false,
88
- breakoutPoints: false,
89
- },
90
- ) => {
91
- const padding = getPadding(editorContainerWidth);
92
- return editorContainerWidth - padding * 2 > akEditorFullWidthLayoutWidth
93
- ? calculateDefaultSnappings()
94
- : calculateDefaultTablePreserveSnappings(lengthOffset, editorContainerWidth, exclude); // lengthOffset was hardcoded 0 here, created PRESERVE_TABLE_SNAPPING_LENGTH_OFFSET instead.
95
- };
96
-
97
- /**
98
- * Returns keys of guidelines that are closest to the table and within the snapGap
99
- */
100
- export const findClosestSnap = (
101
- currentWidth: number,
102
- snapWidths: number[],
103
- guidelines: GuidelineConfig[],
104
- snapGap: number = 0,
105
- tolerance: number = 0,
106
- ) => {
107
- const closestGapIndex = snapWidths.reduce(
108
- (prev, curr, index) =>
109
- Math.abs(curr - currentWidth) < Math.abs(snapWidths[prev] - currentWidth) ? index : prev,
110
- 0,
111
- );
112
- const gap = Math.abs(snapWidths[closestGapIndex] - currentWidth);
113
- if (gap < snapGap) {
114
- const snappingWidth = Math.round(snapWidths[closestGapIndex]);
115
- const guidelineKeys = guidelines.reduce<string[]>((acc, guideline) => {
116
- // NOTE: The snap points are based on the guidelines, however their formatted as a length value whereas the guidelines
117
- // are point based. The point base x coords are calculated by halving the lengths. This means we can convert the
118
- // point base position to length by simply multiplying by 2.
119
- const length = Math.round(
120
- Math.abs(
121
- isVerticalPosition(guideline.position) ? guideline.position.x : guideline.position.y,
122
- ) * 2,
123
- );
124
- if (snappingWidth >= length - tolerance && snappingWidth <= length + tolerance) {
125
- acc.push(guideline.key);
126
- }
127
- return acc;
128
- }, []);
129
-
130
- return {
131
- gap,
132
- keys: guidelineKeys,
133
- };
134
- }
135
- return { gap, keys: [] };
136
- };
@@ -1,60 +0,0 @@
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';
5
- import type { Transaction } from '@atlaskit/editor-prosemirror/state';
6
- import { TableMap } from '@atlaskit/editor-tables/table-map';
7
- import { findTable } from '@atlaskit/editor-tables/utils';
8
-
9
- export const getMergedCellsPositions = (tr: Transaction): number[] => {
10
- const table = findTable(tr.selection);
11
- if (!table) {
12
- return [];
13
- }
14
-
15
- const map = TableMap.get(table.node);
16
- const cellPositions = new Set();
17
- const mergedCells: number[] = [];
18
-
19
- map.map.forEach((value) => {
20
- if (cellPositions.has(value)) {
21
- mergedCells.push(value);
22
- } else {
23
- cellPositions.add(value);
24
- }
25
- });
26
-
27
- return mergedCells;
28
- };
29
-
30
- export const getAssistiveMessage = (
31
- prevTableNode: PmNode,
32
- currentTableNode: PmNode,
33
- intl: IntlShape,
34
- ) => {
35
- const { formatMessage } = intl;
36
- const prevTableMap = TableMap.get(prevTableNode);
37
- const currentTableMap = TableMap.get(currentTableNode);
38
-
39
- if (currentTableMap.width !== prevTableMap.width) {
40
- const diff = Math.abs(currentTableMap.width - prevTableMap.width);
41
- if (currentTableMap.width > prevTableMap.width) {
42
- return formatMessage(messages.columnsAreInserted, { count: diff });
43
- }
44
- if (currentTableMap.width < prevTableMap.width) {
45
- return formatMessage(messages.columnsAreRemoved, { count: diff });
46
- }
47
- }
48
-
49
- if (currentTableMap.height !== prevTableMap.height) {
50
- const diff = Math.abs(currentTableMap.height - prevTableMap.height);
51
- if (currentTableMap.height > prevTableMap.height) {
52
- return formatMessage(messages.rowsAreInserted, { count: diff });
53
- }
54
- if (currentTableMap.height < prevTableMap.height) {
55
- return formatMessage(messages.rowsAreRemoved, { count: diff });
56
- }
57
- }
58
-
59
- return '';
60
- };
@@ -1,13 +0,0 @@
1
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
- import type { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
-
4
- import type { TableDecorations } from '../../types';
5
- import { getDecorations } from '../decorations/plugin';
6
-
7
- import { updateDecorations } from './decoration';
8
-
9
- export const updatePluginStateDecorations = (
10
- state: EditorState,
11
- decorations: Decoration[],
12
- key: TableDecorations,
13
- ): DecorationSet => updateDecorations(state.doc, getDecorations(state), decorations, key);
@@ -1,3 +0,0 @@
1
- export const SORTING_ICON_CLASS_NAME = 'view-mode-sorting-icon';
2
- export const IS_DISABLED_CLASS_NAME = 'is-disabled';
3
- export const SORT_INDEX_DATA_ATTRIBUTE = 'data-sort-index';
@@ -1,291 +0,0 @@
1
- /**
2
- * This plugin allows sorting of table nodes in the Editor without modifying the underlying ProseMirror document.
3
- * Instead of making changes to the ProseMirror document, the plugin sorts the table rows in the DOM. This allows the sorting to be
4
- * visible to the user without affecting the document's content.
5
- */
6
-
7
- import { createElement } from 'react';
8
-
9
- import { RawIntlProvider } from 'react-intl-next';
10
- import uuid from 'uuid/v4';
11
-
12
- import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
13
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
14
- import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
15
- import { SortOrder } from '@atlaskit/editor-common/types';
16
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
17
- import { TableMap } from '@atlaskit/editor-tables/table-map';
18
-
19
- import type tablePlugin from '../../tablePlugin';
20
- import { SortingIconWrapper } from '../../ui/icons/SortingIconWrapper';
21
- import { getPluginState } from '../plugin-factory';
22
-
23
- import {
24
- IS_DISABLED_CLASS_NAME,
25
- SORT_INDEX_DATA_ATTRIBUTE,
26
- SORTING_ICON_CLASS_NAME,
27
- } from './consts';
28
- import { tableViewModeSortPluginKey as key } from './plugin-key';
29
- import type { ViewModeSortPluginState } from './types';
30
- import { getTableElements, toggleSort } from './utils';
31
-
32
- export const createPlugin = (
33
- api: ExtractInjectionAPI<typeof tablePlugin>,
34
- nodeViewPortalProviderAPI: PortalProviderAPI,
35
- ) => {
36
- return new SafePlugin({
37
- state: {
38
- init: () => ({
39
- decorations: DecorationSet.empty,
40
- sort: {},
41
- allTables: [],
42
- }),
43
- apply(tr, pluginState: ViewModeSortPluginState, oldState) {
44
- // TODO: ED-26961 - move this mode check to plugin creation if possible. Right now it's here because the initial state
45
- // does not appear correct when the plugin is created.
46
- const { mode } = api.editorViewMode?.sharedState.currentState() || {};
47
- if (mode !== 'view') {
48
- const sortingDecorations = pluginState?.decorations?.find(
49
- undefined,
50
- undefined,
51
- (s) => s?.type === 'sorting-decoration',
52
- );
53
-
54
- return {
55
- ...pluginState,
56
- decorations: pluginState?.decorations?.remove(sortingDecorations),
57
- };
58
- }
59
- let { decorations, sort, allTables } = pluginState;
60
-
61
- const sortMeta = tr.getMeta('tableSortMeta');
62
-
63
- const hoverTableMeta = tr.getMeta('mouseEnterTable');
64
- const removeTableMeta = tr.getMeta('removeTable');
65
- let tableId = '';
66
-
67
- // Remove the table from the state
68
- if (removeTableMeta) {
69
- allTables = allTables.filter(([id]) => id !== removeTableMeta);
70
- } else {
71
- tableId = hoverTableMeta?.[0];
72
- }
73
-
74
- sort = { ...sort, ...sortMeta };
75
-
76
- const isTableInState = allTables.some(([id]) => id === tableId);
77
-
78
- // Update the table in the state
79
- if (hoverTableMeta) {
80
- allTables = allTables.filter(([id]) => id !== hoverTableMeta[0]);
81
- allTables.push(hoverTableMeta);
82
- }
83
-
84
- /**
85
- * Create decorations for the sorting icons
86
- */
87
- const decs: Decoration[] = [];
88
-
89
- const sortingDecorations = pluginState.decorations.find(
90
- undefined,
91
- undefined,
92
- (spec) => spec.tableId === tableId && spec.type === 'sorting-decoration',
93
- );
94
-
95
- // TODO: ED-26961 - add support for keyboard only users
96
- if (
97
- (hoverTableMeta && !isTableInState) ||
98
- sortMeta ||
99
- (isTableInState && !sortingDecorations.length)
100
- ) {
101
- allTables.forEach((table) => {
102
- const [tableId, _node, pos] = table;
103
- const tableNode = tr.doc.nodeAt(tr.mapping.map(pos));
104
- if (!tableNode || tableNode.type.name !== 'table') {
105
- return pluginState;
106
- }
107
- const map = TableMap.get(tableNode);
108
- const hasMergedCells = new Set(map.map).size !== map.map.length;
109
- map.mapByRow[0].forEach((cell, index) => {
110
- const decorationRenderKey = uuid();
111
- decs.push(
112
- Decoration.widget(
113
- cell + pos + 2,
114
- () => {
115
- const element = document.createElement('div');
116
- element.setAttribute(SORT_INDEX_DATA_ATTRIBUTE, `${index}`);
117
- element.classList.add(SORTING_ICON_CLASS_NAME);
118
- if (hasMergedCells) {
119
- element.classList.add(IS_DISABLED_CLASS_NAME);
120
- }
121
-
122
- let sortOrdered;
123
- if (index === sort[tableId]?.index) {
124
- sortOrdered = sort[tableId]?.direction;
125
- } else {
126
- sortOrdered = SortOrder.NO_ORDER;
127
- }
128
-
129
- const { getIntl } = getPluginState(oldState);
130
-
131
- nodeViewPortalProviderAPI.render(
132
- () =>
133
- createElement(
134
- RawIntlProvider,
135
- { value: getIntl() },
136
- createElement(SortingIconWrapper, {
137
- isSortingAllowed: !hasMergedCells,
138
- sortOrdered,
139
- onClick: () => {},
140
- onKeyDown: () => {},
141
- api,
142
- }),
143
- ),
144
- element,
145
- decorationRenderKey,
146
- undefined,
147
- // @portal-render-immediately
148
- true,
149
- );
150
-
151
- return element;
152
- },
153
- {
154
- destroy: (node) => {
155
- nodeViewPortalProviderAPI.remove(decorationRenderKey);
156
- },
157
- type: 'sorting-decoration',
158
- tableId,
159
- },
160
- ),
161
- );
162
- });
163
- });
164
- decorations = DecorationSet.create(tr.doc, decs);
165
- }
166
-
167
- /**
168
- * Map the decorations to the new document if there are changes
169
- */
170
- if (tr.docChanged) {
171
- decorations = decorations.map(tr.mapping, tr.doc);
172
- allTables = allTables.map((table) => {
173
- return [table[0], table[1], tr.mapping.map(table[2])];
174
- });
175
- }
176
-
177
- return {
178
- decorations,
179
- sort,
180
- allTables,
181
- };
182
- },
183
- },
184
- key,
185
- appendTransaction: (trs, oldState, newState) => {
186
- // return newState.tr;
187
- const { mode } = api?.editorViewMode?.sharedState.currentState() || {};
188
- if (mode !== 'view') {
189
- return newState.tr;
190
- }
191
-
192
- let allTables = key.getState(newState)?.allTables || [];
193
-
194
- /**
195
- * If incoming changes have affected a table node, remove the sorting. This prevents the
196
- * table from breaking if changes like merged cells are incoming.
197
- */
198
- for (const tr of trs) {
199
- const hoverTableMeta = tr.getMeta('mouseEnterTable');
200
- if (hoverTableMeta) {
201
- allTables = allTables.filter(([id]) => id !== hoverTableMeta[0]);
202
- allTables.push(hoverTableMeta);
203
- }
204
- const isRemote = tr.getMeta('isRemote');
205
- const isDocChanged = tr.docChanged;
206
- const isChangesIncoming = isRemote && isDocChanged;
207
-
208
- const oldPluginState = key.getState(oldState);
209
- const newPluginState = key.getState(newState);
210
-
211
- for (const table of allTables) {
212
- const [tableId, node, pos] = table;
213
- const {
214
- order: oldOrder,
215
- direction: oldDirection,
216
- index: oldIndex,
217
- } = oldPluginState?.sort?.[tableId] || {};
218
-
219
- if (isChangesIncoming) {
220
- const maybeTableNode = tr.doc.nodeAt(pos);
221
- const isTableNodeChanged =
222
- maybeTableNode?.attrs?.localId !== tableId || !node.eq(maybeTableNode);
223
-
224
- if (isTableNodeChanged) {
225
- const newtr = newState.tr;
226
- newtr.setMeta('tableSortMeta', {
227
- [tableId]: {},
228
- });
229
- newtr.setMeta('removeTable', tableId);
230
-
231
- // Unsort the table here
232
- if (oldOrder !== undefined) {
233
- const { rows, tbody } = getTableElements(tableId);
234
- if (!rows || !tbody) {
235
- return newtr;
236
- }
237
- const sortedOrder = [...oldOrder].sort((a, b) => a.value - b.value);
238
- sortedOrder.forEach((index, i) => {
239
- tbody.appendChild(rows[index.index + 1]);
240
- });
241
- return newtr;
242
- }
243
- }
244
- }
245
-
246
- /**
247
- * Sort the table if the sort order has changed
248
- */
249
- const {
250
- order: newOrder,
251
- direction: newDirection,
252
- index: newIndex,
253
- } = newPluginState?.sort?.[tableId] || {};
254
- const orderChanged = oldDirection !== newDirection || oldIndex !== newIndex;
255
-
256
- if (orderChanged) {
257
- if (!isRemote && newDirection !== SortOrder.NO_ORDER) {
258
- const { rows, tbody } = getTableElements(tableId);
259
- if (rows && newOrder) {
260
- newOrder.forEach((index, i) => {
261
- tbody?.appendChild(rows[index.value + 1]);
262
- });
263
- }
264
- }
265
- }
266
- }
267
- }
268
- return newState.tr;
269
- },
270
- props: {
271
- handleDOMEvents: {
272
- keydown: (view, event) => {
273
- // TODO: ED-26961 - fix the focus issue here, where toggling sort with a keypress loses focus
274
- if (event.key === 'Enter' || event.key === ' ') {
275
- const pluginState = key.getState(view.state)?.sort || {};
276
- toggleSort(view, event, pluginState);
277
- }
278
- },
279
-
280
- click: (view, event) => {
281
- const pluginState = key.getState(view.state)?.sort || {};
282
- toggleSort(view, event, pluginState);
283
- },
284
- },
285
- decorations(state) {
286
- const decs = key.getState(state)?.decorations || DecorationSet.empty;
287
- return decs;
288
- },
289
- },
290
- });
291
- };
@@ -1,7 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
-
3
- import type { ViewModeSortPluginState } from './types';
4
-
5
- export const tableViewModeSortPluginKey = new PluginKey<ViewModeSortPluginState>(
6
- 'tableViewModeSortPlugin',
7
- );
@@ -1,23 +0,0 @@
1
- import type { SortOrder } from '@atlaskit/editor-common/types';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
-
5
- export type TableSortMeta = Record<
6
- string,
7
- {
8
- index: number;
9
- order: {
10
- index: number;
11
- value: number;
12
- }[];
13
- direction: SortOrder;
14
- }
15
- >;
16
-
17
- export interface ViewModeSortPluginState {
18
- decorations: DecorationSet;
19
- sort: TableSortMeta;
20
- allTables: HoverTableMeta[];
21
- }
22
-
23
- type HoverTableMeta = [string, PMNode, number];
@@ -1,136 +0,0 @@
1
- import { SortOrder } from '@atlaskit/editor-common/types';
2
- import {
3
- convertProsemirrorTableNodeToArrayOfRows,
4
- createCompareNodes,
5
- } from '@atlaskit/editor-common/utils';
6
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
-
9
- import {
10
- IS_DISABLED_CLASS_NAME,
11
- SORT_INDEX_DATA_ATTRIBUTE,
12
- SORTING_ICON_CLASS_NAME,
13
- } from './consts';
14
- import type { TableSortMeta } from './types';
15
-
16
- export const unsort = (oldOrder: { index: number; value: number }[], tableElement: HTMLElement) => {
17
- const tbody = tableElement.querySelector(`:scope > tbody`);
18
- const rows = tableElement.querySelectorAll(`:scope > tbody > tr`);
19
-
20
- const sortedOrder = [...oldOrder].sort((a, b) => a.value - b.value);
21
- sortedOrder.forEach((item) => {
22
- tbody?.appendChild(rows[item.index + 1]);
23
- });
24
- };
25
-
26
- const getSortOrderFromTable = (tableNode: PMNode, sortIndex: number, direction: SortOrder) => {
27
- const tableArray = convertProsemirrorTableNodeToArrayOfRows(tableNode);
28
- tableArray.shift(); // remove header row
29
-
30
- // Keep track of the origin row index
31
- const tableArrayWithIndex = tableArray.map((node, index) => ({
32
- node,
33
- originalIndex: index,
34
- }));
35
-
36
- const compareNodesInOrder = createCompareNodes(
37
- {
38
- // TODO: ED-26961 - add inline card support
39
- getInlineCardTextFromStore() {
40
- return null;
41
- },
42
- },
43
- direction,
44
- );
45
- const order = tableArrayWithIndex
46
- .sort((a, b) => {
47
- return compareNodesInOrder(a.node[sortIndex], b.node[sortIndex]);
48
- })
49
- .map((tableRow, index) => ({
50
- value: tableRow.originalIndex,
51
- index,
52
- }));
53
- return [
54
- // Ensures the first tr is always first in the order
55
- { value: -1, index: -1 },
56
- ...order,
57
- ];
58
- };
59
-
60
- export const toggleSort = (view: EditorView, event: Event, pluginState: TableSortMeta) => {
61
- const target = event.target;
62
- if (!(target instanceof HTMLElement)) {
63
- return;
64
- }
65
- const widget = target.closest(`.${SORTING_ICON_CLASS_NAME}`);
66
- if (widget?.classList.contains(IS_DISABLED_CLASS_NAME) || !widget) {
67
- return;
68
- }
69
- const dataSortIndex = target
70
- ?.closest('.ProseMirror-widget')
71
- ?.getAttribute(SORT_INDEX_DATA_ATTRIBUTE);
72
- const tr = view.state.tr;
73
- const tableElement = target.closest('table');
74
- if (!tableElement || !dataSortIndex) {
75
- return;
76
- }
77
- const tablePos = view.posAtDOM(tableElement, 0);
78
- const tableNode = view.state.doc.nodeAt(tablePos - 1);
79
- const tableId = tableNode?.attrs.localId;
80
-
81
- if (!tableId || !tableNode || tableNode?.type?.name !== 'table') {
82
- return;
83
- }
84
-
85
- // Ignored via go/ees005
86
- // eslint-disable-next-line prefer-const
87
- let { index, direction, order: oldOrder } = pluginState?.[tableId] || {};
88
-
89
- // Unsort if there was already a sort
90
- if (direction !== SortOrder.NO_ORDER && oldOrder !== undefined) {
91
- unsort(oldOrder, tableElement);
92
- }
93
-
94
- const sortIndex = parseInt(dataSortIndex);
95
- if (sortIndex === index) {
96
- switch (direction) {
97
- case SortOrder.NO_ORDER:
98
- direction = SortOrder.ASC;
99
- break;
100
- case SortOrder.ASC:
101
- direction = SortOrder.DESC;
102
- break;
103
- case SortOrder.DESC:
104
- direction = SortOrder.NO_ORDER;
105
- break;
106
- }
107
- } else {
108
- direction = SortOrder.ASC; // default direction when a new index is clicked
109
- }
110
-
111
- const order = getSortOrderFromTable(tableNode, sortIndex, direction);
112
-
113
- if (direction === SortOrder.NO_ORDER) {
114
- tr.setMeta('tableSortMeta', {
115
- [tableId]: {},
116
- });
117
- } else {
118
- tr.setMeta('tableSortMeta', {
119
- [tableId]: {
120
- index: sortIndex,
121
- direction,
122
- order,
123
- tableElement,
124
- },
125
- });
126
- }
127
- view.dispatch(tr);
128
- };
129
-
130
- export const getTableElements = (tableId: string) => {
131
- const tableElement = document.querySelector(`table[data-table-local-id="${tableId}"]`);
132
- const tbody = tableElement?.querySelector(':scope > tbody');
133
-
134
- const rows = tableElement?.querySelectorAll(':scope > tbody > tr');
135
- return { tbody, rows };
136
- };