@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.
- package/CHANGELOG.md +8 -0
- package/package.json +4 -4
- package/afm-cc/tsconfig.json +0 -123
- package/afm-dev-agents/tsconfig.json +0 -123
- package/afm-jira/tsconfig.json +0 -123
- package/afm-passionfruit/tsconfig.json +0 -123
- package/afm-post-office/tsconfig.json +0 -123
- package/afm-rovo-extension/tsconfig.json +0 -123
- package/afm-townsquare/tsconfig.json +0 -123
- package/afm-volt/tsconfig.json +0 -114
- package/build/tsconfig.json +0 -23
- package/docs/0-intro.tsx +0 -57
- package/src/index.ts +0 -21
- package/src/nodeviews/ExternalDropTargets.tsx +0 -91
- package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
- package/src/nodeviews/TableCell.ts +0 -134
- package/src/nodeviews/TableComponent.tsx +0 -1590
- package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
- package/src/nodeviews/TableContainer.tsx +0 -926
- package/src/nodeviews/TableNodeViewBase.ts +0 -29
- package/src/nodeviews/TableResizer.tsx +0 -884
- package/src/nodeviews/TableRow.ts +0 -830
- package/src/nodeviews/TableStickyScrollbar.ts +0 -211
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
- package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
- package/src/nodeviews/table-container-styles.ts +0 -9
- package/src/nodeviews/table-node-views.ts +0 -76
- package/src/nodeviews/table.tsx +0 -530
- package/src/nodeviews/toDOM.ts +0 -244
- package/src/nodeviews/types.ts +0 -36
- package/src/nodeviews/update-overflow-shadows.ts +0 -11
- package/src/pm-plugins/analytics/actions.ts +0 -21
- package/src/pm-plugins/analytics/commands.ts +0 -47
- package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
- package/src/pm-plugins/analytics/plugin-key.ts +0 -5
- package/src/pm-plugins/analytics/plugin.ts +0 -80
- package/src/pm-plugins/analytics/reducer.ts +0 -27
- package/src/pm-plugins/analytics/types.ts +0 -20
- package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
- package/src/pm-plugins/commands/clear.ts +0 -43
- package/src/pm-plugins/commands/collapse.ts +0 -17
- package/src/pm-plugins/commands/column-resize.ts +0 -478
- package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
- package/src/pm-plugins/commands/delete.ts +0 -42
- package/src/pm-plugins/commands/display-mode.ts +0 -18
- package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
- package/src/pm-plugins/commands/hover.ts +0 -242
- package/src/pm-plugins/commands/index.ts +0 -51
- package/src/pm-plugins/commands/insert.ts +0 -438
- package/src/pm-plugins/commands/misc.ts +0 -811
- package/src/pm-plugins/commands/referentiality.ts +0 -15
- package/src/pm-plugins/commands/selection.ts +0 -537
- package/src/pm-plugins/commands/sort.ts +0 -102
- package/src/pm-plugins/commands/split-cell.ts +0 -28
- package/src/pm-plugins/commands/toggle.ts +0 -109
- package/src/pm-plugins/create-plugin-config.ts +0 -17
- package/src/pm-plugins/decorations/plugin.ts +0 -107
- package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
- package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
- package/src/pm-plugins/decorations/utils/types.ts +0 -16
- package/src/pm-plugins/default-table-selection.ts +0 -14
- package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
- package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
- package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
- package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
- package/src/pm-plugins/drag-and-drop/types.ts +0 -18
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
- package/src/pm-plugins/handlers.ts +0 -161
- package/src/pm-plugins/keymap.ts +0 -436
- package/src/pm-plugins/main.ts +0 -433
- package/src/pm-plugins/plugin-factory.ts +0 -42
- package/src/pm-plugins/plugin-key.ts +0 -8
- package/src/pm-plugins/reducer.ts +0 -145
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
- package/src/pm-plugins/sticky-headers/commands.ts +0 -8
- package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
- package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
- package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
- package/src/pm-plugins/sticky-headers/types.ts +0 -20
- package/src/pm-plugins/sticky-headers/util.ts +0 -18
- package/src/pm-plugins/table-analytics.ts +0 -100
- package/src/pm-plugins/table-local-id.ts +0 -213
- package/src/pm-plugins/table-resizing/commands.ts +0 -116
- package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
- package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
- package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
- package/src/pm-plugins/table-resizing/plugin.ts +0 -94
- package/src/pm-plugins/table-resizing/reducer.ts +0 -37
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
- package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
- package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
- package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
- package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
- package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
- package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
- package/src/pm-plugins/table-selection-keymap.ts +0 -64
- package/src/pm-plugins/table-size-selector.ts +0 -39
- package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
- package/src/pm-plugins/table-width.ts +0 -153
- package/src/pm-plugins/transforms/column-width.ts +0 -249
- package/src/pm-plugins/transforms/delete-columns.ts +0 -281
- package/src/pm-plugins/transforms/delete-rows.ts +0 -154
- package/src/pm-plugins/transforms/fix-tables.ts +0 -249
- package/src/pm-plugins/transforms/merge.ts +0 -301
- package/src/pm-plugins/transforms/replace-table.ts +0 -38
- package/src/pm-plugins/transforms/split.ts +0 -90
- package/src/pm-plugins/utils/alignment.ts +0 -33
- package/src/pm-plugins/utils/analytics.ts +0 -238
- package/src/pm-plugins/utils/collapse.ts +0 -93
- package/src/pm-plugins/utils/column-controls.ts +0 -250
- package/src/pm-plugins/utils/create.ts +0 -64
- package/src/pm-plugins/utils/decoration.ts +0 -672
- package/src/pm-plugins/utils/dom.ts +0 -251
- package/src/pm-plugins/utils/drag-menu.tsx +0 -491
- package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
- package/src/pm-plugins/utils/guidelines.ts +0 -30
- package/src/pm-plugins/utils/merged-cells.ts +0 -239
- package/src/pm-plugins/utils/nodes.ts +0 -162
- package/src/pm-plugins/utils/paste.ts +0 -386
- package/src/pm-plugins/utils/row-controls.ts +0 -211
- package/src/pm-plugins/utils/selection.ts +0 -17
- package/src/pm-plugins/utils/snapping.ts +0 -136
- package/src/pm-plugins/utils/table.ts +0 -60
- package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
- package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
- package/src/pm-plugins/view-mode-sort/index.ts +0 -291
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
- package/src/pm-plugins/view-mode-sort/types.ts +0 -23
- package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
- package/src/tablePlugin.tsx +0 -971
- package/src/tablePluginType.ts +0 -102
- package/src/types/index.ts +0 -592
- package/src/ui/ColumnResizeWidget/index.tsx +0 -61
- package/src/ui/ContentComponent.tsx +0 -311
- package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
- package/src/ui/DragHandle/index.tsx +0 -391
- package/src/ui/DragPreview/index.tsx +0 -51
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
- package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
- package/src/ui/FloatingContextualButton/index.tsx +0 -168
- package/src/ui/FloatingContextualButton/styles.ts +0 -69
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
- package/src/ui/FloatingContextualMenu/index.tsx +0 -141
- package/src/ui/FloatingContextualMenu/styles.ts +0 -77
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
- package/src/ui/FloatingDeleteButton/index.tsx +0 -383
- package/src/ui/FloatingDeleteButton/types.ts +0 -3
- package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
- package/src/ui/FloatingDragMenu/index.tsx +0 -136
- package/src/ui/FloatingDragMenu/styles.ts +0 -83
- package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
- package/src/ui/FloatingInsertButton/index.tsx +0 -314
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
- package/src/ui/SizeSelector/index.tsx +0 -74
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
- package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
- package/src/ui/TableFloatingControls/index.tsx +0 -275
- package/src/ui/TableFullWidthLabel/index.tsx +0 -38
- package/src/ui/common-styles.ts +0 -1218
- package/src/ui/consts.ts +0 -109
- package/src/ui/event-handlers.ts +0 -662
- package/src/ui/global-styles.tsx +0 -55
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
- package/src/ui/icons/AddColLeftIcon.tsx +0 -37
- package/src/ui/icons/AddColRightIcon.tsx +0 -37
- package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
- package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
- package/src/ui/icons/DragHandleIcon.tsx +0 -16
- package/src/ui/icons/DragInMotionIcon.tsx +0 -54
- package/src/ui/icons/MergeCellsIcon.tsx +0 -26
- package/src/ui/icons/MinimisedHandle.tsx +0 -15
- package/src/ui/icons/SortingIconWrapper.tsx +0 -43
- package/src/ui/icons/SplitCellIcon.tsx +0 -34
- package/src/ui/toolbar.tsx +0 -1153
- package/src/ui/ui-styles.ts +0 -960
- package/tsconfig.app.json +0 -135
- package/tsconfig.dev.json +0 -54
- package/tsconfig.json +0 -18
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fix an issue that composition text replacement in Safari removes empty nodes during text composition text deletion.
|
|
3
|
-
* https://github.com/ProseMirror/prosemirror/issues/934
|
|
4
|
-
* We will remove this plugin when Webkit fix the problem itself.
|
|
5
|
-
*/
|
|
6
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
-
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
9
|
-
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
|
-
|
|
11
|
-
interface SafariDeleteCompositionTextIssueWorkaroundPluginState {
|
|
12
|
-
renderSpan: boolean;
|
|
13
|
-
decorations: DecorationSet;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const tableSafariDeleteCompositionTextIssueWorkaroundKey =
|
|
17
|
-
new PluginKey<SafariDeleteCompositionTextIssueWorkaroundPluginState>(
|
|
18
|
-
'tableSafariDeleteCompositionTextIssueWorkaround',
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export const createPlugin = () => {
|
|
22
|
-
return new SafePlugin<SafariDeleteCompositionTextIssueWorkaroundPluginState>({
|
|
23
|
-
key: tableSafariDeleteCompositionTextIssueWorkaroundKey,
|
|
24
|
-
state: {
|
|
25
|
-
init: (): SafariDeleteCompositionTextIssueWorkaroundPluginState => ({
|
|
26
|
-
renderSpan: false,
|
|
27
|
-
decorations: DecorationSet.empty,
|
|
28
|
-
}),
|
|
29
|
-
apply: (tr, value): SafariDeleteCompositionTextIssueWorkaroundPluginState => {
|
|
30
|
-
const renderSpan: boolean = tr.getMeta(tableSafariDeleteCompositionTextIssueWorkaroundKey);
|
|
31
|
-
if (typeof renderSpan === 'undefined') {
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let decorations;
|
|
36
|
-
if (renderSpan) {
|
|
37
|
-
// Find position of the first text node in case it has multiple text nodes created by Japanese IME
|
|
38
|
-
const { $from } = tr.selection;
|
|
39
|
-
const pos = $from.before($from.depth);
|
|
40
|
-
const spanDecoration = Decoration.widget(pos, () => {
|
|
41
|
-
const spanElement = document.createElement('span');
|
|
42
|
-
return spanElement;
|
|
43
|
-
});
|
|
44
|
-
decorations = DecorationSet.create(tr.doc, [spanDecoration]);
|
|
45
|
-
} else {
|
|
46
|
-
decorations = DecorationSet.empty;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
renderSpan,
|
|
51
|
-
decorations,
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
props: {
|
|
56
|
-
decorations: (state) =>
|
|
57
|
-
tableSafariDeleteCompositionTextIssueWorkaroundKey.getState(state)?.decorations,
|
|
58
|
-
handleDOMEvents: {
|
|
59
|
-
beforeinput: (view: EditorView, event: Event): boolean => {
|
|
60
|
-
if ((event as InputEvent)?.inputType !== 'deleteCompositionText') {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const selection = window.getSelection();
|
|
64
|
-
if (!selection || selection.rangeCount <= 0 || selection.type !== 'Range') {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const range = selection.getRangeAt(0);
|
|
68
|
-
const { startContainer, endContainer, endOffset, startOffset } = range;
|
|
69
|
-
/**
|
|
70
|
-
* On Safari when composition text is deleted, it deletes any empty elements it finds up the dom tree. Prosemirror can sometimes be confused by this
|
|
71
|
-
* and will think that we meant to delete those elements. This fix forces the resulting node to not be empty.
|
|
72
|
-
* The condition here checks to see if the entire text node is about to be swapped inside of an element
|
|
73
|
-
*/
|
|
74
|
-
if (
|
|
75
|
-
startContainer.nodeType === Node.TEXT_NODE &&
|
|
76
|
-
startContainer === endContainer &&
|
|
77
|
-
startOffset === 0 &&
|
|
78
|
-
endOffset === (startContainer as Text).length
|
|
79
|
-
) {
|
|
80
|
-
const { tr } = view.state;
|
|
81
|
-
tr.setMeta(tableSafariDeleteCompositionTextIssueWorkaroundKey, true);
|
|
82
|
-
view.dispatch(tr);
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
},
|
|
86
|
-
input: (view: EditorView, event: Event): boolean => {
|
|
87
|
-
if ((event as InputEvent)?.inputType !== 'deleteCompositionText') {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
const selection = window.getSelection();
|
|
91
|
-
if (!selection) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
const { tr } = view.state;
|
|
95
|
-
tr.setMeta(tableSafariDeleteCompositionTextIssueWorkaroundKey, false);
|
|
96
|
-
view.dispatch(tr);
|
|
97
|
-
return false;
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createCommand } from './plugin-state';
|
|
2
|
-
import type { RowStickyState } from './types';
|
|
3
|
-
|
|
4
|
-
export const updateStickyState = (rowState: RowStickyState) =>
|
|
5
|
-
createCommand({ name: 'UPDATE', state: rowState }, (tr) => tr.setMeta('addToHistory', false));
|
|
6
|
-
|
|
7
|
-
export const removeStickyState = (pos: number) =>
|
|
8
|
-
createCommand({ name: 'REMOVE', pos }, (tr) => tr.setMeta('addToHistory', false));
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
2
|
-
|
|
3
|
-
import { pluginKey } from './plugin-key';
|
|
4
|
-
import type { StickyPluginAction, StickyPluginState } from './types';
|
|
5
|
-
|
|
6
|
-
const reducer = (pluginState: StickyPluginState, action: StickyPluginAction): StickyPluginState => {
|
|
7
|
-
if (action.name === 'UPDATE') {
|
|
8
|
-
let updated = false;
|
|
9
|
-
const updatedState = pluginState.map((oldTableState) => {
|
|
10
|
-
const replace = oldTableState.pos === action.state.pos;
|
|
11
|
-
|
|
12
|
-
if (replace) {
|
|
13
|
-
updated = true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return replace ? action.state : oldTableState;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (!updated) {
|
|
20
|
-
// new, add it
|
|
21
|
-
updatedState.push(action.state);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return updatedState;
|
|
25
|
-
} else if (action.name === 'REMOVE') {
|
|
26
|
-
return pluginState.filter((rowState) => rowState.pos !== action.pos);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return pluginState;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const { createPluginState, createCommand } = pluginFactory(pluginKey, reducer, {
|
|
33
|
-
mapping: (tr, pluginState) => {
|
|
34
|
-
if (tr.docChanged) {
|
|
35
|
-
return pluginState
|
|
36
|
-
.map((rowInfo) => {
|
|
37
|
-
const remapped = tr.mapping.mapResult(rowInfo.pos);
|
|
38
|
-
return remapped
|
|
39
|
-
? {
|
|
40
|
-
...rowInfo,
|
|
41
|
-
pos: remapped.pos,
|
|
42
|
-
}
|
|
43
|
-
: undefined;
|
|
44
|
-
})
|
|
45
|
-
.filter((f) => f !== undefined) as StickyPluginState;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return pluginState;
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export { createPluginState, createCommand };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
2
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
-
|
|
4
|
-
import { pluginKey } from './plugin-key';
|
|
5
|
-
import { createPluginState } from './plugin-state';
|
|
6
|
-
|
|
7
|
-
export const createPlugin = (dispatch: Dispatch, initialState = () => []) => {
|
|
8
|
-
return new SafePlugin({
|
|
9
|
-
state: createPluginState(dispatch, initialState),
|
|
10
|
-
key: pluginKey,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type RowStickyState = {
|
|
2
|
-
pos: number;
|
|
3
|
-
top: number;
|
|
4
|
-
padding: number;
|
|
5
|
-
sticky: boolean;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type StickyPluginState = RowStickyState[];
|
|
9
|
-
|
|
10
|
-
type UpdateSticky = {
|
|
11
|
-
name: 'UPDATE';
|
|
12
|
-
state: RowStickyState;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type RemoveSticky = {
|
|
16
|
-
name: 'REMOVE';
|
|
17
|
-
pos: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type StickyPluginAction = UpdateSticky | RemoveSticky;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { StickyPluginState } from './types';
|
|
2
|
-
|
|
3
|
-
// only worry about the first row for now
|
|
4
|
-
export const findStickyHeaderForTable = (
|
|
5
|
-
state: StickyPluginState,
|
|
6
|
-
tablePos: number | undefined,
|
|
7
|
-
) => {
|
|
8
|
-
if (!state || tablePos === undefined) {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const rowInfo = state.find((rowInfo) => rowInfo.pos === tablePos + 1);
|
|
13
|
-
if (!rowInfo) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return rowInfo.sticky ? rowInfo : undefined;
|
|
18
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A plugin is created for collecting payload data for tableOverflowChanged analytics event
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
ACTION_SUBJECT,
|
|
6
|
-
EVENT_TYPE,
|
|
7
|
-
TABLE_ACTION,
|
|
8
|
-
TABLE_OVERFLOW_CHANGE_TRIGGER,
|
|
9
|
-
} from '@atlaskit/editor-common/analytics';
|
|
10
|
-
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
11
|
-
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
12
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
13
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
14
|
-
|
|
15
|
-
interface LastTrigger {
|
|
16
|
-
name: TABLE_OVERFLOW_CHANGE_TRIGGER;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type TableAnalyticsPluginState = {
|
|
20
|
-
lastTrigger: LastTrigger | undefined;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const pluginKey = new PluginKey<TableAnalyticsPluginState>('tableOverflowAnalyticsPlugin');
|
|
24
|
-
|
|
25
|
-
export const META_KEYS = {
|
|
26
|
-
OVERFLOW_TRIGGER: 'tableOverflowTrigger',
|
|
27
|
-
OVERFLOW_STATE_CHANGED: 'tableOverflowStateChanged',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const createPlugin = (
|
|
31
|
-
dispatch: Dispatch,
|
|
32
|
-
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
33
|
-
tableResizingEnabled: boolean,
|
|
34
|
-
) =>
|
|
35
|
-
new SafePlugin({
|
|
36
|
-
key: pluginKey,
|
|
37
|
-
state: {
|
|
38
|
-
init() {
|
|
39
|
-
return {
|
|
40
|
-
lastTrigger: undefined,
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
apply(tr, pluginState) {
|
|
44
|
-
const meta = tr.getMeta(META_KEYS.OVERFLOW_TRIGGER);
|
|
45
|
-
const newState = { ...pluginState };
|
|
46
|
-
if (meta) {
|
|
47
|
-
newState.lastTrigger = { ...meta };
|
|
48
|
-
dispatch(pluginKey, newState);
|
|
49
|
-
return newState;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return pluginState;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
appendTransaction: (transactions, oldState, newState) => {
|
|
56
|
-
const newPluginState = pluginKey.getState(newState);
|
|
57
|
-
let hasAnalyticsBeenDispatched = false;
|
|
58
|
-
const lastTriggerName =
|
|
59
|
-
newPluginState?.lastTrigger?.name ||
|
|
60
|
-
// NOTE: We assume that we know and can correctly differentiate
|
|
61
|
-
// between all triggers of table overflow state change.
|
|
62
|
-
// The only trigger we can't identify is viewport width change.
|
|
63
|
-
// However, since there is still a chance that there are other triggers we didn't think of,
|
|
64
|
-
// all these unknown triggers and viwport width change trigger are captured as EXTERNAL.
|
|
65
|
-
TABLE_OVERFLOW_CHANGE_TRIGGER.EXTERNAL;
|
|
66
|
-
|
|
67
|
-
transactions.forEach((tr) => {
|
|
68
|
-
const payload = tr.getMeta(META_KEYS.OVERFLOW_STATE_CHANGED);
|
|
69
|
-
|
|
70
|
-
if (payload) {
|
|
71
|
-
dispatchAnalyticsEvent({
|
|
72
|
-
action: TABLE_ACTION.OVERFLOW_CHANGED,
|
|
73
|
-
actionSubject: ACTION_SUBJECT.TABLE,
|
|
74
|
-
actionSubjectId: null,
|
|
75
|
-
eventType: EVENT_TYPE.TRACK,
|
|
76
|
-
attributes: {
|
|
77
|
-
editorWidth: payload.editorWidth,
|
|
78
|
-
parentWidth: payload.parentWidth,
|
|
79
|
-
isOverflowing: payload.isOverflowing,
|
|
80
|
-
wasOverflowing: payload.wasOverflowing,
|
|
81
|
-
width: payload.width,
|
|
82
|
-
tableResizingEnabled,
|
|
83
|
-
trigger: lastTriggerName,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
hasAnalyticsBeenDispatched = true;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
if (hasAnalyticsBeenDispatched) {
|
|
92
|
-
const tr = newState.tr;
|
|
93
|
-
return tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return undefined;
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
export { createPlugin };
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A plugin for ensuring tables always have unique local IDs, and to
|
|
3
|
-
* preserve/not regenerate them when they are being cut and paste around the
|
|
4
|
-
* document.
|
|
5
|
-
*
|
|
6
|
-
* More broadly, this plugin should be generalised so it can solve this ‘unique
|
|
7
|
-
* id’ problem across the codebase for any node, but for now this will live on
|
|
8
|
-
* its own solving only for tables.
|
|
9
|
-
*
|
|
10
|
-
* TODO: https://product-fabric.atlassian.net/browse/ED-12714
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
import rafSchedule from 'raf-schd';
|
|
14
|
-
|
|
15
|
-
import { uuid } from '@atlaskit/adf-schema';
|
|
16
|
-
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
17
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
18
|
-
import { stepHasSlice } from '@atlaskit/editor-common/utils';
|
|
19
|
-
import type { Node as ProsemirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
20
|
-
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
21
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
22
|
-
|
|
23
|
-
interface TableLocalIdPluginState {
|
|
24
|
-
// One time parse for initial load with existing tables without localIds
|
|
25
|
-
parsedForLocalIds: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const pluginKey = new PluginKey<TableLocalIdPluginState>('tableLocalIdPlugin');
|
|
29
|
-
const getPluginState = (state: EditorState): TableLocalIdPluginState | undefined | null =>
|
|
30
|
-
state && pluginKey.getState(state);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Ensures uniqueness of `localId`s on tables being created or edited
|
|
34
|
-
*/
|
|
35
|
-
const createPlugin = (dispatch: Dispatch) =>
|
|
36
|
-
new SafePlugin<TableLocalIdPluginState>({
|
|
37
|
-
key: pluginKey,
|
|
38
|
-
state: {
|
|
39
|
-
init() {
|
|
40
|
-
return {
|
|
41
|
-
parsedForLocalIds: false,
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
apply(tr, pluginState) {
|
|
45
|
-
const meta = tr.getMeta(pluginKey);
|
|
46
|
-
if (meta) {
|
|
47
|
-
const keys = Object.keys(meta) as Array<keyof TableLocalIdPluginState>;
|
|
48
|
-
const changed = keys.some((key) => {
|
|
49
|
-
return pluginState[key] !== meta[key];
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (changed) {
|
|
53
|
-
const newState = { ...pluginState, ...meta };
|
|
54
|
-
|
|
55
|
-
dispatch(pluginKey, newState);
|
|
56
|
-
return newState;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return pluginState;
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
view: () => {
|
|
64
|
-
return {
|
|
65
|
-
/**
|
|
66
|
-
* Utilise the update cycle for _one_ scan through an initial doc
|
|
67
|
-
* to ensure existing tables without IDs get them when this plugin is
|
|
68
|
-
* enabled.
|
|
69
|
-
*
|
|
70
|
-
* This entire block can be skipped if we simply remove the `checkIsAddingTable`
|
|
71
|
-
* check in appendTransaction, but that comes with 2 cons:
|
|
72
|
-
*
|
|
73
|
-
* 1. require a transaction before we actually add the local IDs
|
|
74
|
-
* 2. ever slightly more unncessary checks
|
|
75
|
-
*
|
|
76
|
-
* Finally, this never happens in practice when utilising this in
|
|
77
|
-
* confluence, as the collab/synchrony initialisation process will
|
|
78
|
-
* trigger a transaction which adds tables, and thus this plugin will
|
|
79
|
-
* add/dedupe the necessary IDs. But general usage of the editor
|
|
80
|
-
* without collab should still solve for IDs.
|
|
81
|
-
*/
|
|
82
|
-
update(editorView) {
|
|
83
|
-
const { state } = editorView;
|
|
84
|
-
const pluginState = getPluginState(state);
|
|
85
|
-
if (!pluginState) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const parsed = pluginState.parsedForLocalIds;
|
|
89
|
-
if (parsed) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { table } = state.schema.nodes;
|
|
94
|
-
rafSchedule(() => {
|
|
95
|
-
const tr = editorView.state.tr;
|
|
96
|
-
let tableIdWasAdded = false;
|
|
97
|
-
editorView.state.doc.descendants((node, pos) => {
|
|
98
|
-
const isTable = node.type === table;
|
|
99
|
-
const localId = node.attrs.localId;
|
|
100
|
-
if (isTable && !localId) {
|
|
101
|
-
tableIdWasAdded = true;
|
|
102
|
-
tr.setNodeMarkup(pos, undefined, {
|
|
103
|
-
...node.attrs,
|
|
104
|
-
localId: uuid.generate(),
|
|
105
|
-
});
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Otherwise continue traversing, we can encounter tables nested in
|
|
110
|
-
* expands/bodiedExtensions
|
|
111
|
-
*/
|
|
112
|
-
return true;
|
|
113
|
-
});
|
|
114
|
-
if (tableIdWasAdded) {
|
|
115
|
-
tr.setMeta('addToHistory', false);
|
|
116
|
-
editorView.dispatch(tr);
|
|
117
|
-
}
|
|
118
|
-
})();
|
|
119
|
-
|
|
120
|
-
editorView.dispatch(
|
|
121
|
-
state.tr.setMeta(pluginKey, {
|
|
122
|
-
parsedForLocalIds: true,
|
|
123
|
-
}),
|
|
124
|
-
);
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
appendTransaction: (transactions, _oldState, newState) => {
|
|
129
|
-
let modified = false;
|
|
130
|
-
const tr = newState.tr;
|
|
131
|
-
const { table } = newState.schema.nodes;
|
|
132
|
-
|
|
133
|
-
const addedTableNodes: Set<ProsemirrorNode> = new Set();
|
|
134
|
-
const addedTableNodePos: Map<ProsemirrorNode, number> = new Map();
|
|
135
|
-
const localIds: Set<string> = new Set();
|
|
136
|
-
|
|
137
|
-
transactions.forEach((transaction) => {
|
|
138
|
-
if (!transaction.docChanged) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Don't interfere with cut as it clashes with fixTables & we don't need
|
|
143
|
-
// to handle any extra cut cases in this plugin
|
|
144
|
-
const uiEvent = transaction.getMeta('uiEvent');
|
|
145
|
-
if (uiEvent === 'cut') {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** Get the tables we are adding and their position */
|
|
150
|
-
for (const step of transaction.steps) {
|
|
151
|
-
if (!stepHasSlice(step)) {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
step.slice.content.descendants((node) => {
|
|
156
|
-
if (node.type === table) {
|
|
157
|
-
addedTableNodes.add(node);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return true;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
if (!addedTableNodes.size) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Get the existing localIds on the page
|
|
170
|
-
newState.doc.descendants((node, pos) => {
|
|
171
|
-
// Skip if this is position of added table
|
|
172
|
-
if (addedTableNodes.has(node)) {
|
|
173
|
-
addedTableNodePos.set(node, pos);
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (node.type !== table) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
localIds.add(node.attrs.localId);
|
|
182
|
-
|
|
183
|
-
// can't have table within a table
|
|
184
|
-
return false;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// If the added nodes have duplicate id, generate a new one
|
|
188
|
-
for (const node of addedTableNodes) {
|
|
189
|
-
if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
|
|
190
|
-
const pos = addedTableNodePos.get(node);
|
|
191
|
-
|
|
192
|
-
if (pos === undefined) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
tr.setNodeMarkup(pos, undefined, {
|
|
197
|
-
...node.attrs,
|
|
198
|
-
localId: uuid.generate(),
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
modified = true;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (modified) {
|
|
206
|
-
return tr;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return;
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
export { createPlugin };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
3
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
-
import { isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
7
|
-
|
|
8
|
-
import type { PluginInjectionAPI } from '../../types';
|
|
9
|
-
import { META_KEYS } from '../table-analytics';
|
|
10
|
-
import { updateColumnWidths } from '../transforms/column-width';
|
|
11
|
-
|
|
12
|
-
import { createCommand, getPluginState } from './plugin-factory';
|
|
13
|
-
import { isClickNear } from './utils/dom';
|
|
14
|
-
import { evenAllColumnsWidths } from './utils/resize-state';
|
|
15
|
-
import type { ResizeState } from './utils/types';
|
|
16
|
-
|
|
17
|
-
export const evenColumns =
|
|
18
|
-
({
|
|
19
|
-
resizeState,
|
|
20
|
-
table,
|
|
21
|
-
start,
|
|
22
|
-
event,
|
|
23
|
-
api,
|
|
24
|
-
}: {
|
|
25
|
-
api: PluginInjectionAPI | undefined | null;
|
|
26
|
-
resizeState: ResizeState;
|
|
27
|
-
table: PMNode;
|
|
28
|
-
start: number;
|
|
29
|
-
event: MouseEvent;
|
|
30
|
-
}): Command =>
|
|
31
|
-
(state, dispatch) => {
|
|
32
|
-
if (!isTableSelected(state.selection)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// double click detection logic
|
|
37
|
-
// Note: ProseMirror's handleDoubleClick doesn't quite work with DOM mousedown event handler
|
|
38
|
-
const { lastClick } = getPluginState(state);
|
|
39
|
-
const now = Date.now();
|
|
40
|
-
if (lastClick && now - lastClick.time < 500 && isClickNear(event, lastClick)) {
|
|
41
|
-
const newState = evenAllColumnsWidths(resizeState);
|
|
42
|
-
setLastClick(null, (tr) => updateColumnWidths(newState, table, start, api)(tr))(
|
|
43
|
-
state,
|
|
44
|
-
dispatch,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setLastClick({ x: event.clientX, y: event.clientY, time: now })(state, dispatch);
|
|
51
|
-
|
|
52
|
-
return false;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const distributeColumnsWidths =
|
|
56
|
-
(
|
|
57
|
-
newResizeState: ResizeState,
|
|
58
|
-
table: ContentNodeWithPos,
|
|
59
|
-
api: PluginInjectionAPI | undefined | null,
|
|
60
|
-
): Command =>
|
|
61
|
-
(state, dispatch) => {
|
|
62
|
-
if (dispatch) {
|
|
63
|
-
const tr = updateColumnWidths(newResizeState, table.node, table.start, api)(state.tr);
|
|
64
|
-
tr.setMeta(META_KEYS.OVERFLOW_TRIGGER, {
|
|
65
|
-
name: TABLE_OVERFLOW_CHANGE_TRIGGER.DISTRIBUTED_COLUMNS,
|
|
66
|
-
});
|
|
67
|
-
stopResizing(tr)(state, dispatch);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return true;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const setResizeHandlePos = (resizeHandlePos: number | null) =>
|
|
74
|
-
createCommand({
|
|
75
|
-
type: 'SET_RESIZE_HANDLE_POSITION',
|
|
76
|
-
data: {
|
|
77
|
-
resizeHandlePos,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
export const stopResizing = (tr?: Transaction) =>
|
|
82
|
-
createCommand(
|
|
83
|
-
{
|
|
84
|
-
type: 'STOP_RESIZING',
|
|
85
|
-
},
|
|
86
|
-
(originalTr) =>
|
|
87
|
-
(tr || originalTr).setMeta('scrollIntoView', false).setMeta('is-resizer-resizing', false),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
export const setDragging = (
|
|
91
|
-
dragging: { startX: number; startWidth: number } | null,
|
|
92
|
-
tr?: Transaction,
|
|
93
|
-
) =>
|
|
94
|
-
createCommand(
|
|
95
|
-
{
|
|
96
|
-
type: 'SET_DRAGGING',
|
|
97
|
-
data: {
|
|
98
|
-
dragging,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
(originalTr) => (tr || originalTr).setMeta('is-resizer-resizing', true),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const setLastClick = (
|
|
105
|
-
lastClick: { x: number; y: number; time: number } | null,
|
|
106
|
-
transform?: (tr: Transaction) => Transaction,
|
|
107
|
-
) =>
|
|
108
|
-
createCommand(
|
|
109
|
-
{
|
|
110
|
-
type: 'SET_LAST_CLICK',
|
|
111
|
-
data: {
|
|
112
|
-
lastClick,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
transform,
|
|
116
|
-
);
|