@atlaskit/editor-plugin-table 5.4.6 → 5.4.8
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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/plugins/table/commands/insert.js +12 -2
- package/dist/cjs/plugins/table/commands/misc.js +63 -13
- package/dist/cjs/plugins/table/index.js +46 -35
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +14 -20
- package/dist/cjs/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/plugins/table/nodeviews/table.js +3 -1
- package/dist/cjs/plugins/table/pm-plugins/analytics/actions.js +14 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/commands.js +45 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-factory.js +13 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin-key.js +8 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/plugin.js +74 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/reducer.js +26 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/types.js +13 -0
- package/dist/cjs/plugins/table/pm-plugins/analytics/utils/moved-event.js +38 -0
- package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/cjs/plugins/table/pm-plugins/main.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/cjs/plugins/table/types.js +2 -1
- package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
- package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
- package/dist/cjs/plugins/table/utils/decoration.js +20 -25
- package/dist/es2019/plugins/table/commands/insert.js +12 -3
- package/dist/es2019/plugins/table/commands/misc.js +54 -4
- package/dist/es2019/plugins/table/index.js +14 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +15 -21
- package/dist/es2019/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/plugins/table/nodeviews/table.js +3 -1
- package/dist/es2019/plugins/table/pm-plugins/analytics/actions.js +8 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/commands.js +33 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/plugin.js +72 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/reducer.js +21 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/types.js +7 -0
- package/dist/es2019/plugins/table/pm-plugins/analytics/utils/moved-event.js +30 -0
- package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/es2019/plugins/table/pm-plugins/main.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/es2019/plugins/table/types.js +2 -1
- package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
- package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
- package/dist/es2019/plugins/table/utils/decoration.js +20 -25
- package/dist/esm/plugins/table/commands/insert.js +12 -3
- package/dist/esm/plugins/table/commands/misc.js +61 -13
- package/dist/esm/plugins/table/index.js +43 -32
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +15 -21
- package/dist/esm/plugins/table/nodeviews/TableResizer.js +1 -1
- package/dist/esm/plugins/table/nodeviews/table.js +3 -1
- package/dist/esm/plugins/table/pm-plugins/analytics/actions.js +8 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/commands.js +39 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin-factory.js +8 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin-key.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/plugin.js +68 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/reducer.js +19 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/types.js +7 -0
- package/dist/esm/plugins/table/pm-plugins/analytics/utils/moved-event.js +31 -0
- package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
- package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
- package/dist/esm/plugins/table/pm-plugins/main.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/esm/plugins/table/types.js +2 -1
- package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
- package/dist/esm/plugins/table/ui/common-styles.js +6 -9
- package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
- package/dist/esm/plugins/table/utils/decoration.js +20 -25
- package/dist/types/plugins/table/commands/misc.d.ts +5 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +2 -0
- package/dist/types/plugins/table/nodeviews/table.d.ts +2 -1
- package/dist/types/plugins/table/nodeviews/types.d.ts +2 -0
- package/dist/types/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
- package/dist/types/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
- package/dist/types/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
- package/dist/types/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
- package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types/plugins/table/types.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/commands/misc.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/nodeviews/table.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/actions.d.ts +17 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/commands.d.ts +5 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-factory.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/plugin.d.ts +4 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/reducer.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/types.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/analytics/utils/moved-event.d.ts +6 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
- package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
- package/package.json +4 -1
- package/src/__tests__/unit/event-handlers.ts +37 -38
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -0
- package/src/__tests__/unit/nodeviews/table.ts +1 -0
- package/src/__tests__/unit/pm-plugins/analytics.ts +327 -0
- package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
- package/src/plugins/table/commands/insert.ts +23 -2
- package/src/plugins/table/commands/misc.ts +93 -8
- package/src/plugins/table/index.tsx +13 -6
- package/src/plugins/table/nodeviews/TableComponent.tsx +35 -44
- package/src/plugins/table/nodeviews/TableResizer.tsx +1 -2
- package/src/plugins/table/nodeviews/table.tsx +4 -0
- package/src/plugins/table/nodeviews/types.ts +2 -0
- package/src/plugins/table/pm-plugins/analytics/actions.ts +23 -0
- package/src/plugins/table/pm-plugins/analytics/commands.ts +53 -0
- package/src/plugins/table/pm-plugins/analytics/plugin-factory.ts +7 -0
- package/src/plugins/table/pm-plugins/analytics/plugin-key.ts +7 -0
- package/src/plugins/table/pm-plugins/analytics/plugin.ts +98 -0
- package/src/plugins/table/pm-plugins/analytics/reducer.ts +27 -0
- package/src/plugins/table/pm-plugins/analytics/types.ts +20 -0
- package/src/plugins/table/pm-plugins/analytics/utils/moved-event.ts +51 -0
- package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
- package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
- package/src/plugins/table/pm-plugins/main.ts +1 -0
- package/src/plugins/table/pm-plugins/table-analytics.ts +1 -1
- package/src/plugins/table/types.ts +2 -1
- package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
- package/src/plugins/table/ui/common-styles.ts +20 -23
- package/src/plugins/table/ui/ui-styles.ts +18 -21
- package/src/plugins/table/utils/decoration.ts +27 -32
- package/tsconfig.dev.json +3 -0
|
@@ -11,20 +11,15 @@ import {
|
|
|
11
11
|
EVENT_TYPE,
|
|
12
12
|
TABLE_ACTION,
|
|
13
13
|
} from '@atlaskit/editor-common/analytics';
|
|
14
|
-
import type {
|
|
14
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
15
15
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
16
|
-
import { createDispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
17
16
|
import { getParentNodeWidth } from '@atlaskit/editor-common/node-width';
|
|
18
17
|
import { tableMarginSides } from '@atlaskit/editor-common/styles';
|
|
19
18
|
import type {
|
|
20
19
|
EditorContainerWidth,
|
|
21
20
|
GetEditorFeatureFlags,
|
|
22
21
|
} from '@atlaskit/editor-common/types';
|
|
23
|
-
import {
|
|
24
|
-
analyticsEventKey,
|
|
25
|
-
browser,
|
|
26
|
-
isValidPosition,
|
|
27
|
-
} from '@atlaskit/editor-common/utils';
|
|
22
|
+
import { browser, isValidPosition } from '@atlaskit/editor-common/utils';
|
|
28
23
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
29
24
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
30
25
|
import {
|
|
@@ -106,6 +101,7 @@ export interface ComponentProps {
|
|
|
106
101
|
ordering: TableColumnOrdering;
|
|
107
102
|
isResizing?: boolean;
|
|
108
103
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
104
|
+
dispatchAnalyticsEvent: DispatchAnalyticsEvent;
|
|
109
105
|
pluginInjectionApi?: PluginInjectionAPI;
|
|
110
106
|
}
|
|
111
107
|
|
|
@@ -487,28 +483,26 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
487
483
|
|
|
488
484
|
const hasHeaderRow = containsHeaderRow(node);
|
|
489
485
|
const rowControls = (
|
|
490
|
-
<
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
/>
|
|
511
|
-
</div>
|
|
486
|
+
<TableFloatingControls
|
|
487
|
+
editorView={view}
|
|
488
|
+
tableRef={tableRef}
|
|
489
|
+
tableNode={node}
|
|
490
|
+
tableActive={tableActive}
|
|
491
|
+
hoveredRows={hoveredRows}
|
|
492
|
+
hoveredCell={hoveredCell}
|
|
493
|
+
isInDanger={isInDanger}
|
|
494
|
+
isResizing={isResizing}
|
|
495
|
+
isNumberColumnEnabled={node.attrs.isNumberColumnEnabled}
|
|
496
|
+
isHeaderRowEnabled={isHeaderRowEnabled}
|
|
497
|
+
isDragAndDropEnabled={isDragAndDropEnabled}
|
|
498
|
+
ordering={ordering}
|
|
499
|
+
isHeaderColumnEnabled={isHeaderColumnEnabled}
|
|
500
|
+
hasHeaderRow={hasHeaderRow}
|
|
501
|
+
// pass `selection` and `tableHeight` to control re-render
|
|
502
|
+
selection={view.state.selection}
|
|
503
|
+
headerRowHeight={headerRow ? headerRow.offsetHeight : undefined}
|
|
504
|
+
stickyHeader={this.state.stickyHeader}
|
|
505
|
+
/>
|
|
512
506
|
);
|
|
513
507
|
|
|
514
508
|
const colControls = isDragAndDropEnabled ? (
|
|
@@ -830,24 +824,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
830
824
|
};
|
|
831
825
|
|
|
832
826
|
private setTimerToSendInitialOverflowCaptured = (isOverflowing: boolean) => {
|
|
833
|
-
const {
|
|
834
|
-
const dispatch: AnalyticsDispatch = createDispatch(eventDispatcher);
|
|
827
|
+
const { dispatchAnalyticsEvent, containerWidth, options } = this.props;
|
|
835
828
|
const parentWidth = this.state?.parentWidth || 0;
|
|
836
829
|
|
|
837
830
|
this.initialOverflowCaptureTimerId = setTimeout(() => {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
parentWidth,
|
|
850
|
-
},
|
|
831
|
+
dispatchAnalyticsEvent({
|
|
832
|
+
action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
|
|
833
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
834
|
+
actionSubjectId: null,
|
|
835
|
+
eventType: EVENT_TYPE.TRACK,
|
|
836
|
+
attributes: {
|
|
837
|
+
editorWidth: containerWidth.width || 0,
|
|
838
|
+
isOverflowing,
|
|
839
|
+
tableResizingEnabled: options?.isTableResizingEnabled || false,
|
|
840
|
+
width: this.node.attrs.width || 0,
|
|
841
|
+
parentWidth,
|
|
851
842
|
},
|
|
852
843
|
});
|
|
853
844
|
|
|
@@ -214,9 +214,8 @@ export const TableResizer = ({
|
|
|
214
214
|
dispatch,
|
|
215
215
|
state: { tr },
|
|
216
216
|
} = editorView;
|
|
217
|
-
tr.setMeta(tableWidthPluginKey, { resizing: true });
|
|
218
217
|
displayGapCursor(false);
|
|
219
|
-
|
|
218
|
+
tr.setMeta(tableWidthPluginKey, { resizing: true });
|
|
220
219
|
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
221
220
|
name: TABLE_OVERFLOW_CHANGE_TRIGGER.RESIZED,
|
|
222
221
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import type { TableColumnOrdering } from '@atlaskit/custom-steps';
|
|
4
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
5
6
|
import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
|
|
6
7
|
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
|
|
@@ -256,6 +257,7 @@ export default class TableView extends ReactNodeView<Props> {
|
|
|
256
257
|
containerWidth={containerWidth!}
|
|
257
258
|
contentDOM={forwardRef}
|
|
258
259
|
getEditorFeatureFlags={props.getEditorFeatureFlags}
|
|
260
|
+
dispatchAnalyticsEvent={props.dispatchAnalyticsEvent}
|
|
259
261
|
pluginInjectionApi={props.pluginInjectionApi}
|
|
260
262
|
/>
|
|
261
263
|
);
|
|
@@ -344,6 +346,7 @@ export const createTableView = (
|
|
|
344
346
|
eventDispatcher: EventDispatcher,
|
|
345
347
|
getEditorContainerWidth: GetEditorContainerWidth,
|
|
346
348
|
getEditorFeatureFlags: GetEditorFeatureFlags,
|
|
349
|
+
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
347
350
|
pluginInjectionApi?: PluginInjectionAPI,
|
|
348
351
|
): NodeView => {
|
|
349
352
|
const {
|
|
@@ -373,6 +376,7 @@ export const createTableView = (
|
|
|
373
376
|
},
|
|
374
377
|
getEditorContainerWidth,
|
|
375
378
|
getEditorFeatureFlags,
|
|
379
|
+
dispatchAnalyticsEvent,
|
|
376
380
|
hasIntlContext,
|
|
377
381
|
pluginInjectionApi,
|
|
378
382
|
}).init();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
3
|
import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
|
|
3
4
|
import type {
|
|
@@ -28,6 +29,7 @@ export interface Props {
|
|
|
28
29
|
options?: TableOptions;
|
|
29
30
|
getEditorContainerWidth: GetEditorContainerWidth;
|
|
30
31
|
getEditorFeatureFlags: GetEditorFeatureFlags;
|
|
32
|
+
dispatchAnalyticsEvent: DispatchAnalyticsEvent;
|
|
31
33
|
hasIntlContext: boolean;
|
|
32
34
|
pluginInjectionApi?: PluginInjectionAPI;
|
|
33
35
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RowOrColumnMovedState } from './types';
|
|
2
|
+
|
|
3
|
+
export enum AnalyticPluginTypes {
|
|
4
|
+
UpdateOverflowTriggerNameAction,
|
|
5
|
+
UpdateRowOrColumnMovedAction,
|
|
6
|
+
RemoveRowOrColumnMovedAction,
|
|
7
|
+
RemoveOverFlowTriggerNameAction,
|
|
8
|
+
UpdateRowOrColumnMovedAndOverflowTrigger,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type UpdateRowOrColumnMovedAction = {
|
|
12
|
+
type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction;
|
|
13
|
+
data: RowOrColumnMovedState;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type RemoveRowOrColumnMovedAction = {
|
|
17
|
+
type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction;
|
|
18
|
+
data: undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type AnalyticPluginAction =
|
|
22
|
+
| UpdateRowOrColumnMovedAction
|
|
23
|
+
| RemoveRowOrColumnMovedAction;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EditorState,
|
|
3
|
+
Transaction,
|
|
4
|
+
} from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
|
|
6
|
+
import { AnalyticPluginTypes } from './actions';
|
|
7
|
+
import { createCommand, getPluginState } from './plugin-factory';
|
|
8
|
+
import { pluginKey } from './plugin-key';
|
|
9
|
+
import type { ActionType, RowOrColumnMovedState } from './types';
|
|
10
|
+
import { getMovedPayload } from './utils/moved-event';
|
|
11
|
+
|
|
12
|
+
export const updateRowOrColumnMoved = (
|
|
13
|
+
nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
|
|
14
|
+
nextAction: ActionType,
|
|
15
|
+
) =>
|
|
16
|
+
createCommand(
|
|
17
|
+
(state) => {
|
|
18
|
+
const { rowOrColumnMoved } = getPluginState(state);
|
|
19
|
+
const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
|
|
23
|
+
data,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// --- transforms, prefer these over commands to avoid an extra 'dispatch'
|
|
30
|
+
export const resetRowOrColumnMovedTransform = () => (tr: Transaction) => {
|
|
31
|
+
const payload = {
|
|
32
|
+
type: AnalyticPluginTypes.RemoveRowOrColumnMovedAction,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return tr.setMeta(pluginKey, payload);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const updateRowOrColumnMovedTransform =
|
|
39
|
+
(
|
|
40
|
+
nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
|
|
41
|
+
nextAction: ActionType,
|
|
42
|
+
) =>
|
|
43
|
+
(state: EditorState, tr: Transaction) => {
|
|
44
|
+
const { rowOrColumnMoved } = getPluginState(state);
|
|
45
|
+
const data = getMovedPayload(nextState, nextAction, rowOrColumnMoved);
|
|
46
|
+
|
|
47
|
+
const payload = {
|
|
48
|
+
type: AnalyticPluginTypes.UpdateRowOrColumnMovedAction,
|
|
49
|
+
data,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return tr.setMeta(pluginKey, payload);
|
|
53
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import {
|
|
3
|
+
ACTION_SUBJECT,
|
|
4
|
+
EVENT_TYPE,
|
|
5
|
+
TABLE_ACTION,
|
|
6
|
+
} from '@atlaskit/editor-common/analytics';
|
|
7
|
+
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
8
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
countCellsInSlice,
|
|
13
|
+
getTableElementMoveTypeBySlice,
|
|
14
|
+
getTableSelectionType,
|
|
15
|
+
isInsideFirstCellOfRowOrColumn,
|
|
16
|
+
} from '../../commands/misc';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
resetRowOrColumnMovedTransform,
|
|
20
|
+
updateRowOrColumnMoved,
|
|
21
|
+
} from './commands';
|
|
22
|
+
import { createPluginState } from './plugin-factory';
|
|
23
|
+
import { pluginKey } from './plugin-key';
|
|
24
|
+
import { defaultState } from './types';
|
|
25
|
+
|
|
26
|
+
export const createPlugin = (
|
|
27
|
+
dispatch: Dispatch,
|
|
28
|
+
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
29
|
+
) =>
|
|
30
|
+
new SafePlugin({
|
|
31
|
+
key: pluginKey,
|
|
32
|
+
state: createPluginState(dispatch, defaultState),
|
|
33
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
34
|
+
const tr = transactions.find((tr) =>
|
|
35
|
+
tr.getMeta(pluginKey)?.data?.currentActions?.includes('pasted'),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (tr) {
|
|
39
|
+
dispatchAnalyticsEvent({
|
|
40
|
+
action: TABLE_ACTION.ROW_OR_COLUMN_MOVED,
|
|
41
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
42
|
+
actionSubjectId: null,
|
|
43
|
+
eventType: EVENT_TYPE.TRACK,
|
|
44
|
+
attributes: {
|
|
45
|
+
type: tr.getMeta(pluginKey)?.data?.type,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return resetRowOrColumnMovedTransform()(tr);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return undefined;
|
|
52
|
+
},
|
|
53
|
+
props: {
|
|
54
|
+
handlePaste: ({ state, dispatch }, event, slice) => {
|
|
55
|
+
if (
|
|
56
|
+
getBooleanFF('platform.editor.table.analytics-plugin-moved-event')
|
|
57
|
+
) {
|
|
58
|
+
const { schema } = state;
|
|
59
|
+
const type = getTableElementMoveTypeBySlice(slice, state);
|
|
60
|
+
|
|
61
|
+
// if the selection wasn't in the first cell of a row or column, don't count it
|
|
62
|
+
if (!isInsideFirstCellOfRowOrColumn(state.selection, type)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const count = countCellsInSlice(slice, schema, type);
|
|
67
|
+
|
|
68
|
+
updateRowOrColumnMoved(
|
|
69
|
+
{
|
|
70
|
+
numberOfCells: count,
|
|
71
|
+
type,
|
|
72
|
+
},
|
|
73
|
+
'pasted',
|
|
74
|
+
)(state, dispatch);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
transformCopied: (slice, { state, dispatch }) => {
|
|
78
|
+
if (
|
|
79
|
+
getBooleanFF('platform.editor.table.analytics-plugin-moved-event')
|
|
80
|
+
) {
|
|
81
|
+
const { schema } = state;
|
|
82
|
+
|
|
83
|
+
const type = getTableSelectionType(state.selection);
|
|
84
|
+
const count = countCellsInSlice(slice, schema, type);
|
|
85
|
+
|
|
86
|
+
updateRowOrColumnMoved(
|
|
87
|
+
{
|
|
88
|
+
numberOfCells: count,
|
|
89
|
+
type,
|
|
90
|
+
},
|
|
91
|
+
'copyOrCut',
|
|
92
|
+
)(state, dispatch);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return slice;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AnalyticPluginTypes } from './actions';
|
|
2
|
+
import type { AnalyticPluginAction } from './actions';
|
|
3
|
+
import type { AnalyticPluginState } from './types';
|
|
4
|
+
import { defaultState } from './types';
|
|
5
|
+
|
|
6
|
+
export const reducer = (
|
|
7
|
+
state: AnalyticPluginState,
|
|
8
|
+
action: AnalyticPluginAction,
|
|
9
|
+
): AnalyticPluginState => {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case AnalyticPluginTypes.UpdateRowOrColumnMovedAction:
|
|
12
|
+
return {
|
|
13
|
+
...state,
|
|
14
|
+
rowOrColumnMoved: {
|
|
15
|
+
...state.rowOrColumnMoved,
|
|
16
|
+
...action.data,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
case AnalyticPluginTypes.RemoveRowOrColumnMovedAction:
|
|
20
|
+
return {
|
|
21
|
+
...state,
|
|
22
|
+
rowOrColumnMoved: defaultState.rowOrColumnMoved,
|
|
23
|
+
};
|
|
24
|
+
default:
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ActionType = 'none' | 'addRowOrColumn' | 'copyOrCut' | 'pasted';
|
|
2
|
+
|
|
3
|
+
export type RowOrColumnMovedState = {
|
|
4
|
+
type?: 'row' | 'column';
|
|
5
|
+
/** used to confirm if same number of cells was copied and pasted */
|
|
6
|
+
numberOfCells?: number;
|
|
7
|
+
currentActions: Array<ActionType>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type AnalyticPluginState = {
|
|
11
|
+
rowOrColumnMoved: RowOrColumnMovedState;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const defaultState = {
|
|
15
|
+
rowOrColumnMoved: {
|
|
16
|
+
type: undefined,
|
|
17
|
+
numberOfCells: undefined,
|
|
18
|
+
currentActions: [],
|
|
19
|
+
},
|
|
20
|
+
} as AnalyticPluginState;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ActionType, RowOrColumnMovedState } from '../types';
|
|
2
|
+
import { defaultState } from '../types';
|
|
3
|
+
|
|
4
|
+
const getNextActionType = (
|
|
5
|
+
nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
|
|
6
|
+
nextAction: ActionType,
|
|
7
|
+
prevState?: RowOrColumnMovedState,
|
|
8
|
+
) => {
|
|
9
|
+
if (nextAction === 'pasted') {
|
|
10
|
+
if (
|
|
11
|
+
prevState &&
|
|
12
|
+
prevState.currentActions.includes('copyOrCut') &&
|
|
13
|
+
prevState.currentActions.includes('addRowOrColumn') &&
|
|
14
|
+
prevState.numberOfCells === nextState.numberOfCells &&
|
|
15
|
+
prevState.type === nextState.type
|
|
16
|
+
) {
|
|
17
|
+
return 'pasted';
|
|
18
|
+
}
|
|
19
|
+
return 'none';
|
|
20
|
+
}
|
|
21
|
+
return nextAction;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getMovedPayload = (
|
|
25
|
+
nextState: Omit<RowOrColumnMovedState, 'currentActions'>,
|
|
26
|
+
nextAction: ActionType,
|
|
27
|
+
prevState: RowOrColumnMovedState,
|
|
28
|
+
) => {
|
|
29
|
+
const nextActionType = getNextActionType(nextState, nextAction, prevState);
|
|
30
|
+
|
|
31
|
+
if (nextActionType === 'none') {
|
|
32
|
+
return defaultState.rowOrColumnMoved;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// a new workflow has started in the opposite axis (e.g. inserted a row, but copied a column) remove old state
|
|
36
|
+
if (prevState.type !== nextState.type) {
|
|
37
|
+
return {
|
|
38
|
+
currentActions: [nextActionType],
|
|
39
|
+
numberOfCells: nextState?.numberOfCells,
|
|
40
|
+
type: nextState.type,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
currentActions: prevState.currentActions.includes(nextActionType)
|
|
46
|
+
? prevState.currentActions
|
|
47
|
+
: [...prevState.currentActions, nextActionType],
|
|
48
|
+
numberOfCells: nextState?.numberOfCells || prevState.numberOfCells,
|
|
49
|
+
type: nextState?.type,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -8,7 +8,6 @@ import type {
|
|
|
8
8
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
11
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
12
11
|
|
|
13
12
|
import { pluginKey as tablePluginKey } from '../plugin-key';
|
|
14
13
|
import { pluginKey as tableWidthPluginKey } from '../table-width';
|
|
@@ -31,11 +30,13 @@ export const handleDocOrSelectionChanged = (
|
|
|
31
30
|
): DecorationSet => {
|
|
32
31
|
const isResizing = tableWidthPluginKey.getState(newState)?.resizing;
|
|
33
32
|
const wasResizing = tableWidthPluginKey.getState(oldState)?.resizing;
|
|
33
|
+
const { isDragAndDropEnabled = false } =
|
|
34
|
+
tablePluginKey.getState(newState) || {};
|
|
34
35
|
|
|
35
36
|
const changedResizing = isResizing !== wasResizing;
|
|
36
37
|
|
|
37
38
|
// Remove column controls when resizing and don't add column decoration controls when DnD enabled
|
|
38
|
-
if (isResizing
|
|
39
|
+
if (isResizing) {
|
|
39
40
|
return DecorationSet.empty;
|
|
40
41
|
} else if (
|
|
41
42
|
tr.docChanged ||
|
|
@@ -45,6 +46,9 @@ export const handleDocOrSelectionChanged = (
|
|
|
45
46
|
return buildColumnControlsDecorations({
|
|
46
47
|
decorationSet,
|
|
47
48
|
tr,
|
|
49
|
+
options: {
|
|
50
|
+
isDragAndDropEnabled,
|
|
51
|
+
},
|
|
48
52
|
});
|
|
49
53
|
} else if (tr.selectionSet) {
|
|
50
54
|
const isTransactionFromMouseClick =
|
|
@@ -70,6 +74,7 @@ export const createPlugin = () => {
|
|
|
70
74
|
|
|
71
75
|
apply: (tr, decorationSet, oldState, newState) => {
|
|
72
76
|
let pluginState = decorationSet;
|
|
77
|
+
// main table plugin --->
|
|
73
78
|
const meta = tr.getMeta(tablePluginKey);
|
|
74
79
|
|
|
75
80
|
if (meta && meta.data && meta.data.decorationSet) {
|
|
@@ -17,7 +17,10 @@ import {
|
|
|
17
17
|
} from '../../../utils/decoration';
|
|
18
18
|
|
|
19
19
|
import { composeDecorations } from './compose-decorations';
|
|
20
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
BuildDecorationTransformerParams,
|
|
22
|
+
DecorationTransformer,
|
|
23
|
+
} from './types';
|
|
21
24
|
|
|
22
25
|
const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
|
|
23
26
|
tr.selection instanceof CellSelection && tr.selection.isColSelection();
|
|
@@ -25,13 +28,12 @@ const isColumnSelected = (tr: Transaction | ReadonlyTransaction): boolean =>
|
|
|
25
28
|
// @see: https://product-fabric.atlassian.net/browse/ED-3796
|
|
26
29
|
const removeControlsHoverDecoration: DecorationTransformer = ({
|
|
27
30
|
decorationSet,
|
|
28
|
-
})
|
|
29
|
-
decorationSet.remove(findControlsHoverDecoration(decorationSet));
|
|
31
|
+
}) => decorationSet.remove(findControlsHoverDecoration(decorationSet));
|
|
30
32
|
|
|
31
33
|
const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
|
|
32
34
|
decorationSet,
|
|
33
35
|
tr,
|
|
34
|
-
})
|
|
36
|
+
}) => {
|
|
35
37
|
if (!isColumnSelected(tr)) {
|
|
36
38
|
return decorationSet;
|
|
37
39
|
}
|
|
@@ -47,10 +49,9 @@ const maybeUpdateColumnSelectedDecoration: DecorationTransformer = ({
|
|
|
47
49
|
const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
|
|
48
50
|
decorationSet,
|
|
49
51
|
tr,
|
|
50
|
-
})
|
|
52
|
+
}) => {
|
|
51
53
|
const table = findTable(tr.selection);
|
|
52
54
|
|
|
53
|
-
// avoid re-drawing state if dnd decorations don't need to be updated
|
|
54
55
|
if (!table) {
|
|
55
56
|
return decorationSet;
|
|
56
57
|
}
|
|
@@ -66,14 +67,13 @@ const maybeUpdateColumnControlsDecoration: DecorationTransformer = ({
|
|
|
66
67
|
// @see: https://product-fabric.atlassian.net/browse/ED-7304
|
|
67
68
|
const removeColumnControlsSelectedDecoration: DecorationTransformer = ({
|
|
68
69
|
decorationSet,
|
|
69
|
-
})
|
|
70
|
-
decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
|
|
70
|
+
}) => decorationSet.remove(findColumnControlSelectedDecoration(decorationSet));
|
|
71
71
|
|
|
72
72
|
const hasColumnSelectedDecorations = (decorationSet: DecorationSet): boolean =>
|
|
73
73
|
!!findColumnControlSelectedDecoration(decorationSet).length;
|
|
74
74
|
|
|
75
75
|
export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer =
|
|
76
|
-
({ decorationSet, tr })
|
|
76
|
+
({ decorationSet, tr }) => {
|
|
77
77
|
if (!hasColumnSelectedDecorations(decorationSet)) {
|
|
78
78
|
return decorationSet;
|
|
79
79
|
}
|
|
@@ -81,10 +81,19 @@ export const maybeUpdateColumnControlsSelectedDecoration: DecorationTransformer
|
|
|
81
81
|
return removeColumnControlsSelectedDecoration({ decorationSet, tr });
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
export const buildColumnControlsDecorations
|
|
84
|
+
export const buildColumnControlsDecorations = ({
|
|
85
85
|
decorationSet,
|
|
86
86
|
tr,
|
|
87
|
-
|
|
87
|
+
options,
|
|
88
|
+
}: BuildDecorationTransformerParams): DecorationSet => {
|
|
89
|
+
if (options.isDragAndDropEnabled) {
|
|
90
|
+
return composeDecorations([
|
|
91
|
+
removeColumnControlsSelectedDecoration,
|
|
92
|
+
removeControlsHoverDecoration,
|
|
93
|
+
maybeUpdateColumnSelectedDecoration,
|
|
94
|
+
])({ decorationSet, tr });
|
|
95
|
+
}
|
|
96
|
+
|
|
88
97
|
return composeDecorations([
|
|
89
98
|
removeColumnControlsSelectedDecoration,
|
|
90
99
|
removeControlsHoverDecoration,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { DecorationTransformer } from './types';
|
|
1
|
+
import type { DecorationTransformer } from './types';
|
|
4
2
|
|
|
5
3
|
export const composeDecorations =
|
|
6
4
|
(transformers: Array<DecorationTransformer>): DecorationTransformer =>
|
|
7
|
-
({ decorationSet, tr })
|
|
5
|
+
({ decorationSet, tr }) =>
|
|
8
6
|
transformers.reduce(
|
|
9
7
|
(decorationSet, transform) => transform({ decorationSet, tr }),
|
|
10
8
|
decorationSet,
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
3
|
ReadonlyTransaction,
|
|
4
4
|
Transaction,
|
|
5
5
|
} from '@atlaskit/editor-prosemirror/state';
|
|
6
|
-
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
7
7
|
|
|
8
|
-
export type DecorationTransformer = (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export type DecorationTransformer = (
|
|
9
|
+
params: DecorationTransformerParams,
|
|
10
|
+
) => DecorationSet;
|
|
11
|
+
|
|
12
|
+
export type DecorationTransformerParams = {
|
|
12
13
|
decorationSet: DecorationSet;
|
|
13
14
|
tr: Transaction | ReadonlyTransaction;
|
|
14
|
-
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type BuildDecorationTransformerParams = DecorationTransformerParams & {
|
|
18
|
+
options: {
|
|
19
|
+
isDragAndDropEnabled: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -309,7 +309,8 @@ export const TableCssClassName = {
|
|
|
309
309
|
CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
|
|
310
310
|
CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
|
|
311
311
|
|
|
312
|
-
/**
|
|
312
|
+
/** drag and drop controls */
|
|
313
|
+
DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
|
|
313
314
|
DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
|
|
314
315
|
DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
|
|
315
316
|
DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
|