@atlaskit/editor-core 188.5.0 → 188.6.0
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 +13 -0
- package/dist/cjs/labs/next/presets/default.js +2 -2
- package/dist/cjs/labs/next/presets/universal.js +1 -6
- package/dist/cjs/plugins/expand/index.js +0 -2
- package/dist/cjs/plugins/expand/nodeviews/index.js +37 -13
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +30 -29
- package/dist/cjs/plugins/status/actions.js +14 -11
- package/dist/cjs/plugins/status/index.js +17 -8
- package/dist/cjs/plugins/status/keymap.js +1 -1
- package/dist/cjs/plugins/status/ui/statusPicker.js +2 -2
- package/dist/cjs/ui/Addon/click-area-helper.js +9 -11
- package/dist/cjs/ui/ContentStyles/index.js +13 -13
- package/dist/cjs/utils/selection.js +12 -14
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/labs/next/presets/default.js +1 -1
- package/dist/es2019/labs/next/presets/universal.js +1 -6
- package/dist/es2019/plugins/expand/index.js +0 -2
- package/dist/es2019/plugins/expand/nodeviews/index.js +37 -13
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -3
- package/dist/es2019/plugins/status/actions.js +3 -2
- package/dist/es2019/plugins/status/index.js +91 -80
- package/dist/es2019/plugins/status/keymap.js +1 -1
- package/dist/es2019/plugins/status/ui/statusPicker.js +1 -1
- package/dist/es2019/ui/Addon/click-area-helper.js +4 -6
- package/dist/es2019/ui/ContentStyles/index.js +1 -1
- package/dist/es2019/utils/selection.js +2 -17
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/labs/next/presets/default.js +1 -1
- package/dist/esm/labs/next/presets/universal.js +1 -6
- package/dist/esm/plugins/expand/index.js +0 -2
- package/dist/esm/plugins/expand/nodeviews/index.js +37 -13
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +30 -29
- package/dist/esm/plugins/status/actions.js +14 -11
- package/dist/esm/plugins/status/index.js +17 -8
- package/dist/esm/plugins/status/keymap.js +1 -1
- package/dist/esm/plugins/status/ui/statusPicker.js +1 -1
- package/dist/esm/ui/Addon/click-area-helper.js +4 -6
- package/dist/esm/ui/ContentStyles/index.js +1 -1
- package/dist/esm/utils/selection.js +2 -13
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/labs/next/presets/default.d.ts +22 -8
- package/dist/types/plugins/expand/index.d.ts +1 -1
- package/dist/types/plugins/expand/nodeviews/index.d.ts +3 -2
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/insert-block/types.d.ts +3 -1
- package/dist/types/plugins/status/actions.d.ts +4 -2
- package/dist/types/plugins/status/index.d.ts +12 -3
- package/dist/types/plugins/status/nodeviews/status.d.ts +1 -1
- package/dist/types/plugins/status/plugin.d.ts +1 -1
- package/dist/types/utils/selection.d.ts +1 -4
- package/package.json +4 -3
- package/dist/cjs/plugins/selection/actions.js +0 -11
- package/dist/cjs/plugins/selection/commands.js +0 -257
- package/dist/cjs/plugins/selection/gap-cursor/actions.js +0 -272
- package/dist/cjs/plugins/selection/gap-cursor/direction.js +0 -23
- package/dist/cjs/plugins/selection/gap-cursor/selection.js +0 -30
- package/dist/cjs/plugins/selection/gap-cursor/styles.js +0 -17
- package/dist/cjs/plugins/selection/gap-cursor/utils/is-ignored.js +0 -12
- package/dist/cjs/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -12
- package/dist/cjs/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -103
- package/dist/cjs/plugins/selection/gap-cursor/utils.js +0 -137
- package/dist/cjs/plugins/selection/gap-cursor-selection.js +0 -37
- package/dist/cjs/plugins/selection/index.js +0 -65
- package/dist/cjs/plugins/selection/plugin-factory.js +0 -49
- package/dist/cjs/plugins/selection/pm-plugins/events/create-selection-between.js +0 -92
- package/dist/cjs/plugins/selection/pm-plugins/events/keydown.js +0 -115
- package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -46
- package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-main.js +0 -160
- package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -8
- package/dist/cjs/plugins/selection/pm-plugins/keymap.js +0 -16
- package/dist/cjs/plugins/selection/pm-plugins/selection-main.js +0 -104
- package/dist/cjs/plugins/selection/reducer.js +0 -26
- package/dist/cjs/plugins/selection/types.js +0 -20
- package/dist/cjs/plugins/selection/utils.js +0 -280
- package/dist/cjs/selection-api/api.js +0 -27
- package/dist/es2019/plugins/selection/actions.js +0 -5
- package/dist/es2019/plugins/selection/commands.js +0 -250
- package/dist/es2019/plugins/selection/gap-cursor/actions.js +0 -270
- package/dist/es2019/plugins/selection/gap-cursor/direction.js +0 -15
- package/dist/es2019/plugins/selection/gap-cursor/selection.js +0 -1
- package/dist/es2019/plugins/selection/gap-cursor/styles.js +0 -145
- package/dist/es2019/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
- package/dist/es2019/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
- package/dist/es2019/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -94
- package/dist/es2019/plugins/selection/gap-cursor/utils.js +0 -124
- package/dist/es2019/plugins/selection/gap-cursor-selection.js +0 -2
- package/dist/es2019/plugins/selection/index.js +0 -51
- package/dist/es2019/plugins/selection/plugin-factory.js +0 -43
- package/dist/es2019/plugins/selection/pm-plugins/events/create-selection-between.js +0 -89
- package/dist/es2019/plugins/selection/pm-plugins/events/keydown.js +0 -112
- package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
- package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-main.js +0 -158
- package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
- package/dist/es2019/plugins/selection/pm-plugins/keymap.js +0 -10
- package/dist/es2019/plugins/selection/pm-plugins/selection-main.js +0 -97
- package/dist/es2019/plugins/selection/reducer.js +0 -18
- package/dist/es2019/plugins/selection/types.js +0 -9
- package/dist/es2019/plugins/selection/utils.js +0 -233
- package/dist/es2019/selection-api/api.js +0 -20
- package/dist/esm/plugins/selection/actions.js +0 -5
- package/dist/esm/plugins/selection/commands.js +0 -251
- package/dist/esm/plugins/selection/gap-cursor/actions.js +0 -266
- package/dist/esm/plugins/selection/gap-cursor/direction.js +0 -15
- package/dist/esm/plugins/selection/gap-cursor/selection.js +0 -1
- package/dist/esm/plugins/selection/gap-cursor/styles.js +0 -10
- package/dist/esm/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
- package/dist/esm/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
- package/dist/esm/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -97
- package/dist/esm/plugins/selection/gap-cursor/utils.js +0 -128
- package/dist/esm/plugins/selection/gap-cursor-selection.js +0 -2
- package/dist/esm/plugins/selection/index.js +0 -58
- package/dist/esm/plugins/selection/plugin-factory.js +0 -43
- package/dist/esm/plugins/selection/pm-plugins/events/create-selection-between.js +0 -86
- package/dist/esm/plugins/selection/pm-plugins/events/keydown.js +0 -110
- package/dist/esm/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
- package/dist/esm/plugins/selection/pm-plugins/gap-cursor-main.js +0 -154
- package/dist/esm/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
- package/dist/esm/plugins/selection/pm-plugins/keymap.js +0 -10
- package/dist/esm/plugins/selection/pm-plugins/selection-main.js +0 -98
- package/dist/esm/plugins/selection/reducer.js +0 -19
- package/dist/esm/plugins/selection/types.js +0 -9
- package/dist/esm/plugins/selection/utils.js +0 -241
- package/dist/esm/selection-api/api.js +0 -21
- package/dist/types/plugins/selection/actions.d.ts +0 -17
- package/dist/types/plugins/selection/commands.d.ts +0 -10
- package/dist/types/plugins/selection/gap-cursor/actions.d.ts +0 -25
- package/dist/types/plugins/selection/gap-cursor/direction.d.ts +0 -10
- package/dist/types/plugins/selection/gap-cursor/selection.d.ts +0 -1
- package/dist/types/plugins/selection/gap-cursor/styles.d.ts +0 -2
- package/dist/types/plugins/selection/gap-cursor/utils/is-ignored.d.ts +0 -1
- package/dist/types/plugins/selection/gap-cursor/utils/is-valid-target-node.d.ts +0 -1
- package/dist/types/plugins/selection/gap-cursor/utils/place-gap-cursor.d.ts +0 -2
- package/dist/types/plugins/selection/gap-cursor/utils.d.ts +0 -8
- package/dist/types/plugins/selection/gap-cursor-selection.d.ts +0 -2
- package/dist/types/plugins/selection/index.d.ts +0 -13
- package/dist/types/plugins/selection/plugin-factory.d.ts +0 -2
- package/dist/types/plugins/selection/pm-plugins/events/create-selection-between.d.ts +0 -4
- package/dist/types/plugins/selection/pm-plugins/events/keydown.d.ts +0 -2
- package/dist/types/plugins/selection/pm-plugins/gap-cursor-keymap.d.ts +0 -2
- package/dist/types/plugins/selection/pm-plugins/gap-cursor-main.d.ts +0 -6
- package/dist/types/plugins/selection/pm-plugins/gap-cursor-plugin-key.d.ts +0 -2
- package/dist/types/plugins/selection/pm-plugins/keymap.d.ts +0 -3
- package/dist/types/plugins/selection/pm-plugins/selection-main.d.ts +0 -7
- package/dist/types/plugins/selection/reducer.d.ts +0 -3
- package/dist/types/plugins/selection/types.d.ts +0 -12
- package/dist/types/plugins/selection/utils.d.ts +0 -58
- package/dist/types/selection-api/api.d.ts +0 -11
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import { findPositionOfNodeBefore } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
6
|
-
import { hideCaretModifier } from '../gap-cursor/styles';
|
|
7
|
-
import { GapCursorSelection, JSON_ID, Side as GapCursorSide, Side } from '../gap-cursor/selection';
|
|
8
|
-
import { getLayoutModeFromTargetNode, isIgnoredClick } from '../gap-cursor/utils';
|
|
9
|
-
import { toDOM } from '../gap-cursor/utils/place-gap-cursor';
|
|
10
|
-
import { deleteNode, setGapCursorAtPos } from '../gap-cursor/actions';
|
|
11
|
-
import { Direction } from '../gap-cursor/direction';
|
|
12
|
-
import { gapCursorPluginKey } from './gap-cursor-plugin-key';
|
|
13
|
-
const plugin = new SafePlugin({
|
|
14
|
-
key: gapCursorPluginKey,
|
|
15
|
-
state: {
|
|
16
|
-
init: () => ({
|
|
17
|
-
selectionIsGapCursor: false,
|
|
18
|
-
displayGapCursor: true
|
|
19
|
-
}),
|
|
20
|
-
apply: (tr, pluginState, _oldState, newState) => {
|
|
21
|
-
var _meta$displayGapCurso;
|
|
22
|
-
const meta = tr.getMeta(gapCursorPluginKey);
|
|
23
|
-
const selectionIsGapCursor = newState.selection instanceof GapCursorSelection;
|
|
24
|
-
return {
|
|
25
|
-
selectionIsGapCursor,
|
|
26
|
-
// only attempt to hide gap cursor if selection is gap cursor
|
|
27
|
-
displayGapCursor: selectionIsGapCursor ? (_meta$displayGapCurso = meta === null || meta === void 0 ? void 0 : meta.displayGapCursor) !== null && _meta$displayGapCurso !== void 0 ? _meta$displayGapCurso : pluginState.displayGapCursor : true
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
view: view => {
|
|
32
|
-
/**
|
|
33
|
-
* If the selection is at the beginning of a document and is a NodeSelection,
|
|
34
|
-
* convert to a GapCursor selection. This is to stop users accidentally replacing
|
|
35
|
-
* the first node of a document by accident.
|
|
36
|
-
*/
|
|
37
|
-
if (view.state.selection.anchor === 0 && view.state.selection instanceof NodeSelection) {
|
|
38
|
-
// This is required otherwise the dispatch doesn't trigger in the correct place
|
|
39
|
-
window.requestAnimationFrame(() => {
|
|
40
|
-
view.dispatch(view.state.tr.setSelection(new GapCursorSelection(view.state.doc.resolve(0), GapCursorSide.LEFT)));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
update(view) {
|
|
45
|
-
const {
|
|
46
|
-
selectionIsGapCursor
|
|
47
|
-
} = gapCursorPluginKey.getState(view.state);
|
|
48
|
-
/**
|
|
49
|
-
* Starting with prosemirror-view 1.19.4, cursor wrapper that previously was hiding cursor doesn't exist:
|
|
50
|
-
* https://github.com/ProseMirror/prosemirror-view/commit/4a56bc7b7e61e96ef879d1dae1014ede0fc09e43
|
|
51
|
-
*
|
|
52
|
-
* Because it was causing issues with RTL: https://github.com/ProseMirror/prosemirror/issues/948
|
|
53
|
-
*
|
|
54
|
-
* This is the work around which uses `caret-color: transparent` in order to hide regular caret,
|
|
55
|
-
* when gap cursor is visible.
|
|
56
|
-
*
|
|
57
|
-
* Browser support is pretty good: https://caniuse.com/#feat=css-caret-color
|
|
58
|
-
*/
|
|
59
|
-
view.dom.classList.toggle(hideCaretModifier, selectionIsGapCursor);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
props: {
|
|
64
|
-
decorations: editorState => {
|
|
65
|
-
const {
|
|
66
|
-
doc,
|
|
67
|
-
selection
|
|
68
|
-
} = editorState;
|
|
69
|
-
const {
|
|
70
|
-
displayGapCursor
|
|
71
|
-
} = gapCursorPluginKey.getState(editorState);
|
|
72
|
-
if (selection instanceof GapCursorSelection && displayGapCursor) {
|
|
73
|
-
const {
|
|
74
|
-
$from,
|
|
75
|
-
side
|
|
76
|
-
} = selection;
|
|
77
|
-
|
|
78
|
-
// render decoration DOM node always to the left of the target node even if selection points to the right
|
|
79
|
-
// otherwise positioning of the right gap cursor is a nightmare when the target node has a nodeView with vertical margins
|
|
80
|
-
let position = selection.head;
|
|
81
|
-
const isRightCursor = side === Side.RIGHT;
|
|
82
|
-
if (isRightCursor && $from.nodeBefore) {
|
|
83
|
-
const nodeBeforeStart = findPositionOfNodeBefore(selection);
|
|
84
|
-
if (typeof nodeBeforeStart === 'number') {
|
|
85
|
-
position = nodeBeforeStart;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const node = isRightCursor ? $from.nodeBefore : $from.nodeAfter;
|
|
89
|
-
const layoutMode = node && getLayoutModeFromTargetNode(node);
|
|
90
|
-
return DecorationSet.create(doc, [Decoration.widget(position, toDOM, {
|
|
91
|
-
key: `${JSON_ID}-${side}-${layoutMode}`,
|
|
92
|
-
side: layoutMode ? -1 : 0
|
|
93
|
-
})]);
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
},
|
|
97
|
-
// render gap cursor only when its valid
|
|
98
|
-
createSelectionBetween(view, $anchor, $head) {
|
|
99
|
-
if (view && view.state && view.state.selection instanceof CellSelection) {
|
|
100
|
-
// Do not show GapCursor when there is a CellSection happening
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
if ($anchor.pos === $head.pos && GapCursorSelection.valid($head)) {
|
|
104
|
-
return new GapCursorSelection($head);
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
},
|
|
108
|
-
handleClick(view, nodePos, event) {
|
|
109
|
-
var _$pos$parent;
|
|
110
|
-
const posAtCoords = view.posAtCoords({
|
|
111
|
-
left: event.clientX,
|
|
112
|
-
top: event.clientY
|
|
113
|
-
});
|
|
114
|
-
if (!posAtCoords || isIgnoredClick(event.target)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
const isInsideTheTarget = posAtCoords.pos === posAtCoords.inside;
|
|
118
|
-
if (isInsideTheTarget) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const leftSideOffsetX = 20;
|
|
122
|
-
const side = event.offsetX > leftSideOffsetX ? Side.RIGHT : Side.LEFT;
|
|
123
|
-
const $pos = view.state.doc.resolve(nodePos);
|
|
124
|
-
// In the new prosemirror-view posAtCoords is not returning a precise value for our media nodes
|
|
125
|
-
if (((_$pos$parent = $pos.parent) === null || _$pos$parent === void 0 ? void 0 : _$pos$parent.type.name) === 'mediaSingle') {
|
|
126
|
-
const $insidePos = view.state.doc.resolve(Math.max(posAtCoords.inside, 0));
|
|
127
|
-
// We don't have GapCursors problems when the node target is inside the root level
|
|
128
|
-
if ($insidePos.depth <= 1) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
const mediaGapCursor = !$pos.nodeBefore ? $pos.before() : $pos.after();
|
|
132
|
-
return setGapCursorAtPos(mediaGapCursor, side)(view.state, view.dispatch);
|
|
133
|
-
}
|
|
134
|
-
const docSize = view.state.doc.content.size;
|
|
135
|
-
const nodeInside = posAtCoords.inside < 0 || posAtCoords.inside > docSize ? null : view.state.doc.nodeAt(posAtCoords.inside);
|
|
136
|
-
if (nodeInside !== null && nodeInside !== void 0 && nodeInside.isAtom) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
return setGapCursorAtPos(nodePos, side)(view.state, view.dispatch);
|
|
140
|
-
},
|
|
141
|
-
handleDOMEvents: {
|
|
142
|
-
/**
|
|
143
|
-
* Android composition events aren't handled well by Prosemirror
|
|
144
|
-
* We've added a couple of beforeinput hooks to help PM out when trying to delete
|
|
145
|
-
* certain nodes. We can remove these when PM has better composition support.
|
|
146
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/543
|
|
147
|
-
*/
|
|
148
|
-
beforeinput: (view, event) => {
|
|
149
|
-
if (event.inputType === 'deleteContentBackward' && view.state.selection instanceof GapCursorSelection) {
|
|
150
|
-
event.preventDefault();
|
|
151
|
-
return deleteNode(Direction.BACKWARD)(view.state, view.dispatch);
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
export default plugin;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { keymap } from '@atlaskit/editor-prosemirror/keymap';
|
|
2
|
-
import { bindKeymapWithCommand, moveRight, moveLeft } from '@atlaskit/editor-common/keymaps';
|
|
3
|
-
import { arrowRight, arrowLeft } from '../commands';
|
|
4
|
-
function keymapPlugin() {
|
|
5
|
-
const list = {};
|
|
6
|
-
bindKeymapWithCommand(moveRight.common, arrowRight, list);
|
|
7
|
-
bindKeymapWithCommand(moveLeft.common, arrowLeft, list);
|
|
8
|
-
return keymap(list);
|
|
9
|
-
}
|
|
10
|
-
export default keymapPlugin;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { SelectionActionTypes } from '../actions';
|
|
4
|
-
import { createPluginState, getPluginState } from '../plugin-factory';
|
|
5
|
-
import { selectionPluginKey } from '../types';
|
|
6
|
-
import { getAllSelectionAnalyticsPayload, getCellSelectionAnalyticsPayload, getDecorations, getNodeSelectionAnalyticsPayload, getRangeSelectionAnalyticsPayload, shouldRecalcDecorations } from '../utils';
|
|
7
|
-
import { onKeydown } from './events/keydown';
|
|
8
|
-
import { onCreateSelectionBetween } from './events/create-selection-between';
|
|
9
|
-
export const getInitialState = state => ({
|
|
10
|
-
decorationSet: getDecorations(state.tr),
|
|
11
|
-
selection: state.selection
|
|
12
|
-
});
|
|
13
|
-
export const createPlugin = (dispatch, dispatchAnalyticsEvent, options = {}) => {
|
|
14
|
-
return new SafePlugin({
|
|
15
|
-
key: selectionPluginKey,
|
|
16
|
-
state: createPluginState(dispatch, getInitialState),
|
|
17
|
-
view: () => ({
|
|
18
|
-
update: (editorView, oldEditorState) => {
|
|
19
|
-
const {
|
|
20
|
-
state
|
|
21
|
-
} = editorView;
|
|
22
|
-
if (!shouldRecalcDecorations({
|
|
23
|
-
oldEditorState,
|
|
24
|
-
newEditorState: state
|
|
25
|
-
})) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const analyticsPayload = getNodeSelectionAnalyticsPayload(state.selection) || getAllSelectionAnalyticsPayload(state.selection) ||
|
|
29
|
-
// We handle all range/cell selections except click and drag here, which is
|
|
30
|
-
// handled in mouseup handler below
|
|
31
|
-
!editorView.mouseDown && (getRangeSelectionAnalyticsPayload(state.selection, state.doc) || getCellSelectionAnalyticsPayload(state));
|
|
32
|
-
|
|
33
|
-
// We have to use dispatchAnalyticsEvent over any of the analytics plugin helpers
|
|
34
|
-
// as there were several issues caused by the fact that adding analytics through
|
|
35
|
-
// the plugin adds a new step to the transaction
|
|
36
|
-
// This causes prosemirror to run through some different code paths, eg. attempting
|
|
37
|
-
// to map selection
|
|
38
|
-
if (analyticsPayload) {
|
|
39
|
-
dispatchAnalyticsEvent(analyticsPayload);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}),
|
|
43
|
-
appendTransaction(_transactions, oldEditorState, newEditorState) {
|
|
44
|
-
if (!shouldRecalcDecorations({
|
|
45
|
-
oldEditorState,
|
|
46
|
-
newEditorState
|
|
47
|
-
})) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const {
|
|
51
|
-
tr
|
|
52
|
-
} = newEditorState;
|
|
53
|
-
tr.setMeta(selectionPluginKey, {
|
|
54
|
-
type: SelectionActionTypes.SET_DECORATIONS,
|
|
55
|
-
selection: tr.selection,
|
|
56
|
-
decorationSet: getDecorations(tr)
|
|
57
|
-
});
|
|
58
|
-
return tr;
|
|
59
|
-
},
|
|
60
|
-
filterTransaction(tr, state) {
|
|
61
|
-
// Prevent single click selecting atom nodes on mobile (we want to select with long press gesture instead)
|
|
62
|
-
if (options.useLongPressSelection && tr.selectionSet && tr.selection instanceof NodeSelection && !tr.getMeta(selectionPluginKey)) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Prevent prosemirror's mutation observer overriding a node selection with a text selection
|
|
67
|
-
// for exact same range - this was cause of being unable to change dates in collab:
|
|
68
|
-
// https://product-fabric.atlassian.net/browse/ED-10645
|
|
69
|
-
if (state.selection instanceof NodeSelection && tr.selection instanceof TextSelection && state.selection.from === tr.selection.from && state.selection.to === tr.selection.to) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
73
|
-
},
|
|
74
|
-
props: {
|
|
75
|
-
createSelectionBetween: onCreateSelectionBetween,
|
|
76
|
-
decorations(state) {
|
|
77
|
-
return getPluginState(state).decorationSet;
|
|
78
|
-
},
|
|
79
|
-
handleDOMEvents: {
|
|
80
|
-
keydown: onKeydown,
|
|
81
|
-
// We only want to fire analytics for a click and drag range/cell selection when
|
|
82
|
-
// the user has finished, otherwise we will get an event almost every time they move
|
|
83
|
-
// their mouse which is too much
|
|
84
|
-
mouseup: (editorView, event) => {
|
|
85
|
-
const mouseEvent = event;
|
|
86
|
-
if (!mouseEvent.shiftKey) {
|
|
87
|
-
const analyticsPayload = getRangeSelectionAnalyticsPayload(editorView.state.selection, editorView.state.doc) || getCellSelectionAnalyticsPayload(editorView.state);
|
|
88
|
-
if (analyticsPayload) {
|
|
89
|
-
dispatchAnalyticsEvent(analyticsPayload);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SelectionActionTypes } from './actions';
|
|
2
|
-
export function reducer(pluginState, action) {
|
|
3
|
-
switch (action.type) {
|
|
4
|
-
case SelectionActionTypes.SET_DECORATIONS:
|
|
5
|
-
return {
|
|
6
|
-
...pluginState,
|
|
7
|
-
decorationSet: action.decorationSet,
|
|
8
|
-
selection: action.selection
|
|
9
|
-
};
|
|
10
|
-
case SelectionActionTypes.SET_RELATIVE_SELECTION:
|
|
11
|
-
return {
|
|
12
|
-
...pluginState,
|
|
13
|
-
selectionRelativeToNode: action.selectionRelativeToNode
|
|
14
|
-
};
|
|
15
|
-
default:
|
|
16
|
-
return pluginState;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { RelativeSelectionPos } from '@atlaskit/editor-common/selection';
|
|
3
|
-
export const selectionPluginKey = new PluginKey('selection');
|
|
4
|
-
export { RelativeSelectionPos };
|
|
5
|
-
export let SelectionDirection = /*#__PURE__*/function (SelectionDirection) {
|
|
6
|
-
SelectionDirection[SelectionDirection["Before"] = -1] = "Before";
|
|
7
|
-
SelectionDirection[SelectionDirection["After"] = 1] = "After";
|
|
8
|
-
return SelectionDirection;
|
|
9
|
-
}({});
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { NodeSelection, TextSelection, Selection, AllSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
import { flatten, findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
-
import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
|
|
5
|
-
import { isSelectionAtStartOfNode, isSelectionAtEndOfNode, getNodeSelectionAnalyticsPayload, getAllSelectionAnalyticsPayload, getRangeSelectionAnalyticsPayload, getCellSelectionAnalyticsPayload, createSelectionClickHandler, isIgnored as isIgnoredByGapCursor } from '@atlaskit/editor-common/selection';
|
|
6
|
-
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
7
|
-
import { selectionPluginKey } from './types';
|
|
8
|
-
export const getDecorations = tr => {
|
|
9
|
-
if (tr.selection instanceof NodeSelection) {
|
|
10
|
-
return DecorationSet.create(tr.doc, [Decoration.node(tr.selection.from, tr.selection.to, {
|
|
11
|
-
class: akEditorSelectedNodeClassName
|
|
12
|
-
})]);
|
|
13
|
-
}
|
|
14
|
-
if (tr.selection instanceof TextSelection || tr.selection instanceof AllSelection) {
|
|
15
|
-
const decorations = getNodesToDecorateFromSelection(tr.selection, tr.doc).map(({
|
|
16
|
-
node,
|
|
17
|
-
pos
|
|
18
|
-
}) => {
|
|
19
|
-
return Decoration.node(pos, pos + node.nodeSize, {
|
|
20
|
-
class: akEditorSelectedNodeClassName
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
return DecorationSet.create(tr.doc, decorations);
|
|
24
|
-
}
|
|
25
|
-
return DecorationSet.empty;
|
|
26
|
-
};
|
|
27
|
-
const topLevelBlockNodesThatHaveSelectionStyles = ['table', 'panel', 'expand', 'layoutSection', 'decisionList', 'decisionItem', 'codeBlock'];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Use `getNodesToDecorateFromSelection` to collect and return
|
|
31
|
-
* a list of nodes within the Selection that should have Selection
|
|
32
|
-
* decorations applied. This allows selection styles to be added to
|
|
33
|
-
* nested nodes. It will ignore text nodes as decorations are
|
|
34
|
-
* applied natively and also ignore nodes that don't completely
|
|
35
|
-
* sit within the given `Selection`.
|
|
36
|
-
*/
|
|
37
|
-
export const getNodesToDecorateFromSelection = (selection, doc) => {
|
|
38
|
-
const nodes = [];
|
|
39
|
-
if (selection.from !== selection.to) {
|
|
40
|
-
const {
|
|
41
|
-
from,
|
|
42
|
-
to
|
|
43
|
-
} = selection;
|
|
44
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
45
|
-
const withinSelection = from <= pos && pos + node.nodeSize <= to;
|
|
46
|
-
// The reason we need to check for these nodes is to stop
|
|
47
|
-
// traversing their children if they are within a selection -
|
|
48
|
-
// this is to prevent selection styles from being added to
|
|
49
|
-
// the children as well as the parent node.
|
|
50
|
-
// Example scenario is if an entire table has been selected
|
|
51
|
-
// we should not traverse its children so we can apply the
|
|
52
|
-
// selection styles to the table. But if an entire tableRow
|
|
53
|
-
// has been selected (but the parent table has not) we should
|
|
54
|
-
// traverse it as it could contain other nodes that need
|
|
55
|
-
// selection styles. I couldn’t see a clear way to differentiate
|
|
56
|
-
// without explicitly stating which nodes should be traversed
|
|
57
|
-
// and which shouldn’t.
|
|
58
|
-
const isTopLevelNodeThatHasSelectionStyles = topLevelBlockNodesThatHaveSelectionStyles.includes(node.type.name);
|
|
59
|
-
// If the node is a top-level block node and completely sits within
|
|
60
|
-
// the selection, we do not recurse it's children to prevent selection
|
|
61
|
-
// styles being added to its child nodes. The expected behaviour
|
|
62
|
-
// is that selection styles are only added to the parent.
|
|
63
|
-
if (node && withinSelection && isTopLevelNodeThatHasSelectionStyles) {
|
|
64
|
-
nodes.push({
|
|
65
|
-
node,
|
|
66
|
-
pos
|
|
67
|
-
});
|
|
68
|
-
return false;
|
|
69
|
-
// Otherwise we recurse the children and return them so we can apply
|
|
70
|
-
// selection styles. Text is handled by the browser.
|
|
71
|
-
} else if (node && withinSelection && !node.isText) {
|
|
72
|
-
nodes.push({
|
|
73
|
-
node,
|
|
74
|
-
pos
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return nodes;
|
|
81
|
-
};
|
|
82
|
-
export function shouldRecalcDecorations({
|
|
83
|
-
oldEditorState,
|
|
84
|
-
newEditorState
|
|
85
|
-
}) {
|
|
86
|
-
const oldSelection = oldEditorState.selection;
|
|
87
|
-
const newSelection = newEditorState.selection;
|
|
88
|
-
const oldPluginState = selectionPluginKey.getState(oldEditorState);
|
|
89
|
-
const newPluginState = selectionPluginKey.getState(newEditorState);
|
|
90
|
-
if (!oldPluginState || !newPluginState) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If selection is unchanged, no need to recalculate
|
|
95
|
-
if (oldSelection.eq(newSelection)) {
|
|
96
|
-
// We need this special case for NodeSelection, as Prosemirror still thinks the
|
|
97
|
-
// selections are equal when the node has changed
|
|
98
|
-
if (oldSelection instanceof NodeSelection && newSelection instanceof NodeSelection) {
|
|
99
|
-
const oldDecorations = oldPluginState.decorationSet.find();
|
|
100
|
-
const newDecorations = newPluginState.decorationSet.find();
|
|
101
|
-
// There might not be old or new decorations if the node selection is for a text node
|
|
102
|
-
// This wouldn't have happened intentionally, but we need to handle this case regardless
|
|
103
|
-
if (oldDecorations.length > 0 && newDecorations.length > 0) {
|
|
104
|
-
return !oldDecorations[0].eq(newDecorations[0]);
|
|
105
|
-
}
|
|
106
|
-
return !(oldDecorations.length === 0 && newDecorations.length === 0);
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// There's no point updating decorations if going from one standard TextSelection to another
|
|
112
|
-
if (oldSelection instanceof TextSelection && newSelection instanceof TextSelection && oldSelection.from === oldSelection.to && newSelection.from === newSelection.to) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
export const isSelectableContainerNode = node => !!(node && !node.isAtom && NodeSelection.isSelectable(node));
|
|
118
|
-
export const isSelectableChildNode = node => !!(node && (node.isText || isEmptyParagraph(node) || NodeSelection.isSelectable(node)));
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Finds closest parent node that is a selectable block container node
|
|
122
|
-
* If it finds a parent that is not selectable but supports gap cursor, will
|
|
123
|
-
* return undefined
|
|
124
|
-
*/
|
|
125
|
-
export const findSelectableContainerParent = selection => {
|
|
126
|
-
let foundNodeThatSupportsGapCursor = false;
|
|
127
|
-
const selectableNode = findParentNode(node => {
|
|
128
|
-
const isSelectable = isSelectableContainerNode(node);
|
|
129
|
-
if (!isSelectable && !isIgnoredByGapCursor(node)) {
|
|
130
|
-
foundNodeThatSupportsGapCursor = true;
|
|
131
|
-
}
|
|
132
|
-
return isSelectable;
|
|
133
|
-
})(selection);
|
|
134
|
-
if (!foundNodeThatSupportsGapCursor) {
|
|
135
|
-
return selectableNode;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Finds node before that is a selectable block container node, starting
|
|
141
|
-
* from $pos.depth + 1 and working in
|
|
142
|
-
* If it finds a node that is not selectable but supports gap cursor, will
|
|
143
|
-
* return undefined
|
|
144
|
-
*/
|
|
145
|
-
export const findSelectableContainerBefore = ($pos, doc) => {
|
|
146
|
-
// prosemirror just returns the same pos from Selection.findFrom when
|
|
147
|
-
// parent.inlineContent is true, so we move position back one here
|
|
148
|
-
// to counteract that
|
|
149
|
-
if ($pos.parent.inlineContent && isSelectableContainerNode($pos.parent)) {
|
|
150
|
-
$pos = doc.resolve($pos.start() - 1);
|
|
151
|
-
}
|
|
152
|
-
const selectionBefore = Selection.findFrom($pos, -1);
|
|
153
|
-
if (selectionBefore) {
|
|
154
|
-
const $selectionBefore = doc.resolve(selectionBefore.from);
|
|
155
|
-
for (let i = $pos.depth + 1; i <= $selectionBefore.depth; i++) {
|
|
156
|
-
const node = $selectionBefore.node(i);
|
|
157
|
-
if (isSelectableContainerNode(node)) {
|
|
158
|
-
return {
|
|
159
|
-
node,
|
|
160
|
-
pos: $selectionBefore.start(i) - 1
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (i > $pos.depth + 1 && !isIgnoredByGapCursor(node)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Stick to the default left selection behaviour,
|
|
170
|
-
* useful for mediaSingleWithCaption
|
|
171
|
-
*/
|
|
172
|
-
if (selectionBefore instanceof NodeSelection && NodeSelection.isSelectable(selectionBefore.node)) {
|
|
173
|
-
return {
|
|
174
|
-
node: selectionBefore.node,
|
|
175
|
-
pos: selectionBefore.from
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Finds node after that is a selectable block container node, starting
|
|
183
|
-
* from $pos.depth + 1 and working in
|
|
184
|
-
* If it finds a node that is not selectable but supports gap cursor, will
|
|
185
|
-
* return undefined
|
|
186
|
-
*/
|
|
187
|
-
export const findSelectableContainerAfter = ($pos, doc) => {
|
|
188
|
-
const selectionAfter = Selection.findFrom($pos, 1);
|
|
189
|
-
if (selectionAfter) {
|
|
190
|
-
const $selectionAfter = doc.resolve(selectionAfter.from);
|
|
191
|
-
for (let i = $pos.depth + 1; i <= $selectionAfter.depth; i++) {
|
|
192
|
-
const node = $selectionAfter.node(i);
|
|
193
|
-
if (isSelectableContainerNode(node)) {
|
|
194
|
-
return {
|
|
195
|
-
node,
|
|
196
|
-
pos: $selectionAfter.start(i) - 1
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (i > $pos.depth + 1 && !isIgnoredByGapCursor(node)) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Finds first child node that is a selectable block container node OR that
|
|
208
|
-
* supports gap cursor
|
|
209
|
-
*/
|
|
210
|
-
export const findFirstChildNodeToSelect = parent => flatten(parent).find(child => isSelectableChildNode(child.node) || !isIgnoredByGapCursor(child.node));
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Finds last child node that is a selectable block container node OR that
|
|
214
|
-
* supports gap cursor
|
|
215
|
-
*/
|
|
216
|
-
export const findLastChildNodeToSelect = parent => {
|
|
217
|
-
let child;
|
|
218
|
-
parent.descendants((node, pos) => {
|
|
219
|
-
if (isSelectableChildNode(node) || !isIgnoredByGapCursor(node)) {
|
|
220
|
-
child = {
|
|
221
|
-
node,
|
|
222
|
-
pos
|
|
223
|
-
};
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
if (child) {
|
|
228
|
-
return child;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
export const isSelectionAtStartOfParentNode = ($pos, selection) => isSelectionAtStartOfNode($pos, findSelectableContainerParent(selection));
|
|
232
|
-
export const isSelectionAtEndOfParentNode = ($pos, selection) => isSelectionAtEndOfNode($pos, findSelectableContainerParent(selection));
|
|
233
|
-
export { getNodeSelectionAnalyticsPayload, getAllSelectionAnalyticsPayload, getRangeSelectionAnalyticsPayload, getCellSelectionAnalyticsPayload, createSelectionClickHandler };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { setSelectionRelativeToNode as setSelectionRelativeToNodeOriginalCommand } from '../plugins/selection/commands';
|
|
2
|
-
import { getPluginState as getSelectionPluginState } from '../plugins/selection/plugin-factory';
|
|
3
|
-
export const createEditorSelectionAPI = () => {
|
|
4
|
-
return {
|
|
5
|
-
getSelectionPluginState: state => {
|
|
6
|
-
return getSelectionPluginState(state);
|
|
7
|
-
},
|
|
8
|
-
setSelectionRelativeToNode: ({
|
|
9
|
-
selectionRelativeToNode,
|
|
10
|
-
selection
|
|
11
|
-
}) => state => {
|
|
12
|
-
let tr = state.tr;
|
|
13
|
-
const fakeDispatch = _tr => {
|
|
14
|
-
tr = _tr;
|
|
15
|
-
};
|
|
16
|
-
setSelectionRelativeToNodeOriginalCommand(selectionRelativeToNode, selection)(state, fakeDispatch);
|
|
17
|
-
return tr;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
};
|