@atlaskit/editor-plugin-table 5.4.6 → 5.4.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/table/commands/insert.js +12 -2
- package/dist/cjs/plugins/table/commands/misc.js +49 -1
- package/dist/cjs/plugins/table/index.js +46 -35
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +12 -16
- 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/main.js +1 -1
- package/dist/cjs/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/es2019/plugins/table/commands/insert.js +12 -3
- package/dist/es2019/plugins/table/commands/misc.js +49 -0
- package/dist/es2019/plugins/table/index.js +14 -4
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +13 -17
- 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/main.js +1 -1
- package/dist/es2019/plugins/table/pm-plugins/table-analytics.js +1 -1
- package/dist/esm/plugins/table/commands/insert.js +12 -3
- package/dist/esm/plugins/table/commands/misc.js +48 -0
- package/dist/esm/plugins/table/index.js +43 -32
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +13 -17
- 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/main.js +1 -1
- package/dist/esm/plugins/table/pm-plugins/table-analytics.js +1 -1
- 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-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/package.json +4 -1
- 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/plugins/table/commands/insert.ts +23 -2
- package/src/plugins/table/commands/misc.ts +84 -1
- package/src/plugins/table/index.tsx +13 -6
- package/src/plugins/table/nodeviews/TableComponent.tsx +15 -22
- 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/main.ts +1 -0
- package/src/plugins/table/pm-plugins/table-analytics.ts +1 -1
- 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
|
|
|
@@ -830,24 +826,21 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
830
826
|
};
|
|
831
827
|
|
|
832
828
|
private setTimerToSendInitialOverflowCaptured = (isOverflowing: boolean) => {
|
|
833
|
-
const {
|
|
834
|
-
const dispatch: AnalyticsDispatch = createDispatch(eventDispatcher);
|
|
829
|
+
const { dispatchAnalyticsEvent, containerWidth, options } = this.props;
|
|
835
830
|
const parentWidth = this.state?.parentWidth || 0;
|
|
836
831
|
|
|
837
832
|
this.initialOverflowCaptureTimerId = setTimeout(() => {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
parentWidth,
|
|
850
|
-
},
|
|
833
|
+
dispatchAnalyticsEvent({
|
|
834
|
+
action: TABLE_ACTION.INITIAL_OVERFLOW_CAPTURED,
|
|
835
|
+
actionSubject: ACTION_SUBJECT.TABLE,
|
|
836
|
+
actionSubjectId: null,
|
|
837
|
+
eventType: EVENT_TYPE.TRACK,
|
|
838
|
+
attributes: {
|
|
839
|
+
editorWidth: containerWidth.width || 0,
|
|
840
|
+
isOverflowing,
|
|
841
|
+
tableResizingEnabled: options?.isTableResizingEnabled || false,
|
|
842
|
+
width: this.node.attrs.width || 0,
|
|
843
|
+
parentWidth,
|
|
851
844
|
},
|
|
852
845
|
});
|
|
853
846
|
|
|
@@ -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
|
+
};
|
package/tsconfig.dev.json
CHANGED