@atlaskit/editor-plugin-table 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +2 -11
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -62,280 +62,285 @@ const TABLE_BREAKOUT_NAME_MAPPING = {
62
62
  };
63
63
 
64
64
  // #region Analytics wrappers
65
- export const emptyMultipleCellsWithAnalytics = (
66
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
67
- ) => (
68
- inputMethod:
69
- | INPUT_METHOD.CONTEXT_MENU
70
- | INPUT_METHOD.KEYBOARD
71
- | INPUT_METHOD.FLOATING_TB,
72
- targetCellPosition?: number,
73
- ) =>
74
- withEditorAnalyticsAPI(({ selection }) => {
75
- const {
76
- horizontalCells,
77
- verticalCells,
78
- totalRowCount,
79
- totalColumnCount,
80
- } = getSelectedCellInfo(selection);
81
-
82
- return {
83
- action: TABLE_ACTION.CLEARED,
84
- actionSubject: ACTION_SUBJECT.TABLE,
85
- actionSubjectId: null,
86
- attributes: {
87
- inputMethod,
65
+ export const emptyMultipleCellsWithAnalytics =
66
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
67
+ (
68
+ inputMethod:
69
+ | INPUT_METHOD.CONTEXT_MENU
70
+ | INPUT_METHOD.KEYBOARD
71
+ | INPUT_METHOD.FLOATING_TB,
72
+ targetCellPosition?: number,
73
+ ) =>
74
+ withEditorAnalyticsAPI(({ selection }) => {
75
+ const {
88
76
  horizontalCells,
89
77
  verticalCells,
90
78
  totalRowCount,
91
79
  totalColumnCount,
92
- },
93
- eventType: EVENT_TYPE.TRACK,
94
- };
95
- })(editorAnalyticsAPI)(clearMultipleCells(targetCellPosition));
96
-
97
- export const mergeCellsWithAnalytics = (
98
- editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined,
99
- ) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) =>
100
- withEditorAnalyticsAPI(({ selection }) => {
101
- const {
102
- horizontalCells,
103
- verticalCells,
104
- totalCells,
105
- totalRowCount,
106
- totalColumnCount,
107
- } = getSelectedCellInfo(selection);
80
+ } = getSelectedCellInfo(selection);
108
81
 
109
- return {
110
- action: TABLE_ACTION.MERGED,
111
- actionSubject: ACTION_SUBJECT.TABLE,
112
- actionSubjectId: null,
113
- attributes: {
114
- inputMethod,
82
+ return {
83
+ action: TABLE_ACTION.CLEARED,
84
+ actionSubject: ACTION_SUBJECT.TABLE,
85
+ actionSubjectId: null,
86
+ attributes: {
87
+ inputMethod,
88
+ horizontalCells,
89
+ verticalCells,
90
+ totalRowCount,
91
+ totalColumnCount,
92
+ },
93
+ eventType: EVENT_TYPE.TRACK,
94
+ };
95
+ })(editorAnalyticsAPI)(clearMultipleCells(targetCellPosition));
96
+
97
+ export const mergeCellsWithAnalytics =
98
+ (editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined) =>
99
+ (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) =>
100
+ withEditorAnalyticsAPI(({ selection }) => {
101
+ const {
115
102
  horizontalCells,
116
103
  verticalCells,
117
104
  totalCells,
118
105
  totalRowCount,
119
106
  totalColumnCount,
120
- },
121
- eventType: EVENT_TYPE.TRACK,
122
- };
123
- })(editorAnalyticsAPI)((state, dispatch) => {
124
- if (dispatch) {
125
- dispatch(mergeCells(state.tr));
126
- }
127
- return true;
128
- });
129
-
130
- export const splitCellWithAnalytics = (
131
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
132
- ) => (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) =>
133
- withEditorAnalyticsAPI(({ selection }) => {
134
- const { totalRowCount, totalColumnCount } = getSelectedCellInfo(selection);
135
- const cell = findCellClosestToPos(selection.$anchor);
136
- if (cell) {
137
- const {
138
- rowspan: verticalCells,
139
- colspan: horizontalCells,
140
- } = cell.node.attrs;
107
+ } = getSelectedCellInfo(selection);
141
108
 
142
109
  return {
143
- action: TABLE_ACTION.SPLIT,
110
+ action: TABLE_ACTION.MERGED,
144
111
  actionSubject: ACTION_SUBJECT.TABLE,
145
112
  actionSubjectId: null,
146
113
  attributes: {
147
114
  inputMethod,
148
115
  horizontalCells,
149
116
  verticalCells,
150
- totalCells: horizontalCells * verticalCells,
117
+ totalCells,
151
118
  totalRowCount,
152
119
  totalColumnCount,
153
120
  },
154
121
  eventType: EVENT_TYPE.TRACK,
155
122
  };
156
- }
157
- return;
158
- })(editorAnalyticsAPI)(splitCell);
159
-
160
- export const setColorWithAnalytics = (
161
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
162
- ) => (
163
- inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
164
- cellColor: string,
165
- targetCellPosition?: number,
166
- ) =>
167
- withEditorAnalyticsAPI(({ selection }) => {
168
- const {
169
- horizontalCells,
170
- verticalCells,
171
- totalCells,
172
- totalRowCount,
173
- totalColumnCount,
174
- } = getSelectedCellInfo(selection);
175
-
176
- return {
177
- action: TABLE_ACTION.COLORED,
178
- actionSubject: ACTION_SUBJECT.TABLE,
179
- actionSubjectId: null,
180
- attributes: {
181
- inputMethod,
182
- cellColor: (
183
- tableBackgroundColorPalette.get(cellColor.toLowerCase()) || cellColor
184
- ).toLowerCase(),
123
+ })(editorAnalyticsAPI)((state, dispatch) => {
124
+ if (dispatch) {
125
+ dispatch(mergeCells(state.tr));
126
+ }
127
+ return true;
128
+ });
129
+
130
+ export const splitCellWithAnalytics =
131
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
132
+ (inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB) =>
133
+ withEditorAnalyticsAPI(({ selection }) => {
134
+ const { totalRowCount, totalColumnCount } =
135
+ getSelectedCellInfo(selection);
136
+ const cell = findCellClosestToPos(selection.$anchor);
137
+ if (cell) {
138
+ const { rowspan: verticalCells, colspan: horizontalCells } =
139
+ cell.node.attrs;
140
+
141
+ return {
142
+ action: TABLE_ACTION.SPLIT,
143
+ actionSubject: ACTION_SUBJECT.TABLE,
144
+ actionSubjectId: null,
145
+ attributes: {
146
+ inputMethod,
147
+ horizontalCells,
148
+ verticalCells,
149
+ totalCells: horizontalCells * verticalCells,
150
+ totalRowCount,
151
+ totalColumnCount,
152
+ },
153
+ eventType: EVENT_TYPE.TRACK,
154
+ };
155
+ }
156
+ return;
157
+ })(editorAnalyticsAPI)(splitCell);
158
+
159
+ export const setColorWithAnalytics =
160
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
161
+ (
162
+ inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
163
+ cellColor: string,
164
+ targetCellPosition?: number,
165
+ ) =>
166
+ withEditorAnalyticsAPI(({ selection }) => {
167
+ const {
185
168
  horizontalCells,
186
169
  verticalCells,
187
170
  totalCells,
188
171
  totalRowCount,
189
172
  totalColumnCount,
190
- },
191
- eventType: EVENT_TYPE.TRACK,
192
- };
193
- })(editorAnalyticsAPI)(
194
- setMultipleCellAttrs({ background: cellColor }, targetCellPosition),
195
- );
173
+ } = getSelectedCellInfo(selection);
196
174
 
197
- export const addRowAroundSelection = (
198
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
199
- ) => (side: RowInsertPosition): Command => (state, dispatch) => {
200
- const { selection } = state;
201
- const isCellSelection = selection instanceof CellSelection;
202
- const rect = isCellSelection
203
- ? getSelectionRect(selection)
204
- : findCellRectClosestToPos(selection.$from);
205
-
206
- if (!rect) {
207
- return false;
208
- }
209
-
210
- const position =
211
- isCellSelection && side === 'TOP' ? rect.top : rect.bottom - 1;
212
-
213
- const offset = side === 'BOTTOM' ? 1 : 0;
214
-
215
- return insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, {
216
- index: position + offset,
217
- moveCursorToInsertedRow: false,
218
- })(state, dispatch);
219
- };
220
-
221
- export const insertRowWithAnalytics = (
222
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
223
- ) => (inputMethod: InsertRowMethods, options: InsertRowOptions) =>
224
- withEditorAnalyticsAPI((state) => {
225
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
226
- state.selection,
175
+ return {
176
+ action: TABLE_ACTION.COLORED,
177
+ actionSubject: ACTION_SUBJECT.TABLE,
178
+ actionSubjectId: null,
179
+ attributes: {
180
+ inputMethod,
181
+ cellColor: (
182
+ tableBackgroundColorPalette.get(cellColor.toLowerCase()) ||
183
+ cellColor
184
+ ).toLowerCase(),
185
+ horizontalCells,
186
+ verticalCells,
187
+ totalCells,
188
+ totalRowCount,
189
+ totalColumnCount,
190
+ },
191
+ eventType: EVENT_TYPE.TRACK,
192
+ };
193
+ })(editorAnalyticsAPI)(
194
+ setMultipleCellAttrs({ background: cellColor }, targetCellPosition),
227
195
  );
228
- return {
229
- action: TABLE_ACTION.ADDED_ROW,
230
- actionSubject: ACTION_SUBJECT.TABLE,
231
- actionSubjectId: null,
232
- attributes: {
233
- inputMethod,
234
- position: options.index,
235
- totalRowCount,
236
- totalColumnCount,
237
- },
238
- eventType: EVENT_TYPE.TRACK,
239
- };
240
- })(editorAnalyticsAPI)(
241
- insertRow(options.index, options.moveCursorToInsertedRow),
242
- );
243
196
 
244
- export const insertColumnWithAnalytics = (
245
- getEditorContainerWidth: GetEditorContainerWidth,
246
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
247
- ) => (
248
- inputMethod:
249
- | INPUT_METHOD.CONTEXT_MENU
250
- | INPUT_METHOD.BUTTON
251
- | INPUT_METHOD.SHORTCUT
252
- | INPUT_METHOD.FLOATING_TB,
253
- position: number,
254
- ) =>
255
- withEditorAnalyticsAPI((state) => {
256
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
257
- state.selection,
258
- );
259
- return {
260
- action: TABLE_ACTION.ADDED_COLUMN,
261
- actionSubject: ACTION_SUBJECT.TABLE,
262
- actionSubjectId: null,
263
- attributes: {
264
- inputMethod,
265
- position,
266
- totalRowCount,
267
- totalColumnCount,
268
- },
269
- eventType: EVENT_TYPE.TRACK,
270
- };
271
- })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth)(position));
197
+ export const addRowAroundSelection =
198
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
199
+ (side: RowInsertPosition): Command =>
200
+ (state, dispatch) => {
201
+ const { selection } = state;
202
+ const isCellSelection = selection instanceof CellSelection;
203
+ const rect = isCellSelection
204
+ ? getSelectionRect(selection)
205
+ : findCellRectClosestToPos(selection.$from);
206
+
207
+ if (!rect) {
208
+ return false;
209
+ }
272
210
 
273
- export const deleteRowsWithAnalytics = (
274
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
275
- ) => (
276
- inputMethod:
277
- | INPUT_METHOD.CONTEXT_MENU
278
- | INPUT_METHOD.BUTTON
279
- | INPUT_METHOD.FLOATING_TB,
280
- rect: Rect,
281
- isHeaderRowRequired: boolean,
282
- ) =>
283
- withEditorAnalyticsAPI(({ selection }) => {
284
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
211
+ const position =
212
+ isCellSelection && side === 'TOP' ? rect.top : rect.bottom - 1;
285
213
 
286
- return {
287
- action: TABLE_ACTION.DELETED_ROW,
288
- actionSubject: ACTION_SUBJECT.TABLE,
289
- actionSubjectId: null,
290
- attributes: {
291
- inputMethod,
292
- position: rect.top,
293
- count: rect.bottom - rect.top,
294
- totalRowCount,
295
- totalColumnCount,
296
- },
297
- eventType: EVENT_TYPE.TRACK,
298
- };
299
- })(editorAnalyticsAPI)((state, dispatch) => {
300
- if (dispatch) {
301
- dispatch(deleteRows(rect, isHeaderRowRequired)(state.tr));
302
- }
303
- return true;
304
- });
214
+ const offset = side === 'BOTTOM' ? 1 : 0;
305
215
 
306
- export const deleteColumnsWithAnalytics = (
307
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
308
- ) => (
309
- inputMethod:
310
- | INPUT_METHOD.CONTEXT_MENU
311
- | INPUT_METHOD.BUTTON
312
- | INPUT_METHOD.FLOATING_TB,
313
- rect: Rect,
314
- ) =>
315
- withEditorAnalyticsAPI(({ selection }) => {
316
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(selection);
216
+ return insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT, {
217
+ index: position + offset,
218
+ moveCursorToInsertedRow: false,
219
+ })(state, dispatch);
220
+ };
317
221
 
318
- return {
319
- action: TABLE_ACTION.DELETED_COLUMN,
320
- actionSubject: ACTION_SUBJECT.TABLE,
321
- actionSubjectId: null,
322
- attributes: {
323
- inputMethod,
324
- position: rect.left,
325
- count: rect.right - rect.left,
326
- totalRowCount,
327
- totalColumnCount,
328
- },
329
- eventType: EVENT_TYPE.TRACK,
330
- };
331
- })(editorAnalyticsAPI)((state, dispatch) => {
332
- if (dispatch) {
333
- dispatch(
334
- deleteColumns(rect, getAllowAddColumnCustomStep(state))(state.tr),
222
+ export const insertRowWithAnalytics =
223
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
224
+ (inputMethod: InsertRowMethods, options: InsertRowOptions) =>
225
+ withEditorAnalyticsAPI((state) => {
226
+ const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
227
+ state.selection,
335
228
  );
336
- }
337
- return true;
338
- });
229
+ return {
230
+ action: TABLE_ACTION.ADDED_ROW,
231
+ actionSubject: ACTION_SUBJECT.TABLE,
232
+ actionSubjectId: null,
233
+ attributes: {
234
+ inputMethod,
235
+ position: options.index,
236
+ totalRowCount,
237
+ totalColumnCount,
238
+ },
239
+ eventType: EVENT_TYPE.TRACK,
240
+ };
241
+ })(editorAnalyticsAPI)(
242
+ insertRow(options.index, options.moveCursorToInsertedRow),
243
+ );
244
+
245
+ export const insertColumnWithAnalytics =
246
+ (
247
+ getEditorContainerWidth: GetEditorContainerWidth,
248
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
249
+ ) =>
250
+ (
251
+ inputMethod:
252
+ | INPUT_METHOD.CONTEXT_MENU
253
+ | INPUT_METHOD.BUTTON
254
+ | INPUT_METHOD.SHORTCUT
255
+ | INPUT_METHOD.FLOATING_TB,
256
+ position: number,
257
+ ) =>
258
+ withEditorAnalyticsAPI((state) => {
259
+ const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
260
+ state.selection,
261
+ );
262
+ return {
263
+ action: TABLE_ACTION.ADDED_COLUMN,
264
+ actionSubject: ACTION_SUBJECT.TABLE,
265
+ actionSubjectId: null,
266
+ attributes: {
267
+ inputMethod,
268
+ position,
269
+ totalRowCount,
270
+ totalColumnCount,
271
+ },
272
+ eventType: EVENT_TYPE.TRACK,
273
+ };
274
+ })(editorAnalyticsAPI)(insertColumn(getEditorContainerWidth)(position));
275
+
276
+ export const deleteRowsWithAnalytics =
277
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
278
+ (
279
+ inputMethod:
280
+ | INPUT_METHOD.CONTEXT_MENU
281
+ | INPUT_METHOD.BUTTON
282
+ | INPUT_METHOD.FLOATING_TB,
283
+ rect: Rect,
284
+ isHeaderRowRequired: boolean,
285
+ ) =>
286
+ withEditorAnalyticsAPI(({ selection }) => {
287
+ const { totalRowCount, totalColumnCount } =
288
+ getSelectedTableInfo(selection);
289
+
290
+ return {
291
+ action: TABLE_ACTION.DELETED_ROW,
292
+ actionSubject: ACTION_SUBJECT.TABLE,
293
+ actionSubjectId: null,
294
+ attributes: {
295
+ inputMethod,
296
+ position: rect.top,
297
+ count: rect.bottom - rect.top,
298
+ totalRowCount,
299
+ totalColumnCount,
300
+ },
301
+ eventType: EVENT_TYPE.TRACK,
302
+ };
303
+ })(editorAnalyticsAPI)((state, dispatch) => {
304
+ if (dispatch) {
305
+ dispatch(deleteRows(rect, isHeaderRowRequired)(state.tr));
306
+ }
307
+ return true;
308
+ });
309
+
310
+ export const deleteColumnsWithAnalytics =
311
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
312
+ (
313
+ inputMethod:
314
+ | INPUT_METHOD.CONTEXT_MENU
315
+ | INPUT_METHOD.BUTTON
316
+ | INPUT_METHOD.FLOATING_TB,
317
+ rect: Rect,
318
+ ) =>
319
+ withEditorAnalyticsAPI(({ selection }) => {
320
+ const { totalRowCount, totalColumnCount } =
321
+ getSelectedTableInfo(selection);
322
+
323
+ return {
324
+ action: TABLE_ACTION.DELETED_COLUMN,
325
+ actionSubject: ACTION_SUBJECT.TABLE,
326
+ actionSubjectId: null,
327
+ attributes: {
328
+ inputMethod,
329
+ position: rect.left,
330
+ count: rect.right - rect.left,
331
+ totalRowCount,
332
+ totalColumnCount,
333
+ },
334
+ eventType: EVENT_TYPE.TRACK,
335
+ };
336
+ })(editorAnalyticsAPI)((state, dispatch) => {
337
+ if (dispatch) {
338
+ dispatch(
339
+ deleteColumns(rect, getAllowAddColumnCustomStep(state))(state.tr),
340
+ );
341
+ }
342
+ return true;
343
+ });
339
344
 
340
345
  const getTableDeletedAnalytics = (
341
346
  selection: Selection,
@@ -361,12 +366,12 @@ export const deleteTableWithAnalytics = (
361
366
  getTableDeletedAnalytics(selection, INPUT_METHOD.FLOATING_TB),
362
367
  )(editorAnalyticsAPI)(deleteTable);
363
368
 
364
- export const deleteTableIfSelectedWithAnalytics = (
365
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
366
- ) => (inputMethod: INPUT_METHOD.FLOATING_TB | INPUT_METHOD.KEYBOARD) =>
367
- withEditorAnalyticsAPI(({ selection }) =>
368
- getTableDeletedAnalytics(selection, inputMethod),
369
- )(editorAnalyticsAPI)(deleteTableIfSelected);
369
+ export const deleteTableIfSelectedWithAnalytics =
370
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
371
+ (inputMethod: INPUT_METHOD.FLOATING_TB | INPUT_METHOD.KEYBOARD) =>
372
+ withEditorAnalyticsAPI(({ selection }) =>
373
+ getTableDeletedAnalytics(selection, inputMethod),
374
+ )(editorAnalyticsAPI)(deleteTableIfSelected);
370
375
 
371
376
  export const toggleHeaderRowWithAnalytics = (
372
377
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
@@ -458,56 +463,56 @@ export const toggleTableLayoutWithAnalytics = (
458
463
  return;
459
464
  })(editorAnalyticsAPI)(toggleTableLayout);
460
465
 
461
- export const sortColumnWithAnalytics = (
462
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
463
- ) => (
464
- inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
465
- columnIndex: number,
466
- sortOrder: SortOrder,
467
- ) =>
468
- withEditorAnalyticsAPI((state) => {
469
- const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
470
- state.selection,
471
- );
472
- return {
473
- action: TABLE_ACTION.SORTED_COLUMN,
474
- actionSubject: ACTION_SUBJECT.TABLE,
475
- attributes: {
476
- inputMethod,
477
- totalRowCount,
478
- totalColumnCount,
479
- position: columnIndex,
480
- sortOrder,
481
- mode: 'editor',
482
- },
483
- eventType: EVENT_TYPE.TRACK,
484
- };
485
- })(editorAnalyticsAPI)(sortByColumn(columnIndex, sortOrder));
486
-
487
- export const distributeColumnsWidthsWithAnalytics = (
488
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
489
- ) => (
490
- inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
491
- { resizeState, table, attributes }: ResizeStateWithAnalytics,
492
- ) => {
493
- return withEditorAnalyticsAPI(() => {
494
- return {
495
- action: TABLE_ACTION.DISTRIBUTED_COLUMNS_WIDTHS,
496
- actionSubject: ACTION_SUBJECT.TABLE,
497
- actionSubjectId: null,
498
- attributes: {
499
- inputMethod,
500
- ...attributes,
501
- },
502
- eventType: EVENT_TYPE.TRACK,
503
- };
504
- })(editorAnalyticsAPI)((state, dispatch) => {
505
- if (dispatch) {
506
- distributeColumnsWidths(resizeState, table)(state, dispatch);
507
- }
508
- return true;
509
- });
510
- };
466
+ export const sortColumnWithAnalytics =
467
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
468
+ (
469
+ inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
470
+ columnIndex: number,
471
+ sortOrder: SortOrder,
472
+ ) =>
473
+ withEditorAnalyticsAPI((state) => {
474
+ const { totalRowCount, totalColumnCount } = getSelectedTableInfo(
475
+ state.selection,
476
+ );
477
+ return {
478
+ action: TABLE_ACTION.SORTED_COLUMN,
479
+ actionSubject: ACTION_SUBJECT.TABLE,
480
+ attributes: {
481
+ inputMethod,
482
+ totalRowCount,
483
+ totalColumnCount,
484
+ position: columnIndex,
485
+ sortOrder,
486
+ mode: 'editor',
487
+ },
488
+ eventType: EVENT_TYPE.TRACK,
489
+ };
490
+ })(editorAnalyticsAPI)(sortByColumn(columnIndex, sortOrder));
491
+
492
+ export const distributeColumnsWidthsWithAnalytics =
493
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
494
+ (
495
+ inputMethod: INPUT_METHOD.CONTEXT_MENU | INPUT_METHOD.FLOATING_TB,
496
+ { resizeState, table, attributes }: ResizeStateWithAnalytics,
497
+ ) => {
498
+ return withEditorAnalyticsAPI(() => {
499
+ return {
500
+ action: TABLE_ACTION.DISTRIBUTED_COLUMNS_WIDTHS,
501
+ actionSubject: ACTION_SUBJECT.TABLE,
502
+ actionSubjectId: null,
503
+ attributes: {
504
+ inputMethod,
505
+ ...attributes,
506
+ },
507
+ eventType: EVENT_TYPE.TRACK,
508
+ };
509
+ })(editorAnalyticsAPI)((state, dispatch) => {
510
+ if (dispatch) {
511
+ distributeColumnsWidths(resizeState, table)(state, dispatch);
512
+ }
513
+ return true;
514
+ });
515
+ };
511
516
 
512
517
  export const wrapTableInExpandWithAnalytics = (
513
518
  editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,