@atlaskit/editor-core 188.5.0 → 188.5.2
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 +7 -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/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/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/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/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,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.selectionPlugin = exports.default = void 0;
|
|
8
|
-
var _selectionMain = require("./pm-plugins/selection-main");
|
|
9
|
-
var _types = require("./types");
|
|
10
|
-
var _keymap = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
11
|
-
var _gapCursorMain = _interopRequireDefault(require("./pm-plugins/gap-cursor-main"));
|
|
12
|
-
var _gapCursorPluginKey = require("./pm-plugins/gap-cursor-plugin-key");
|
|
13
|
-
var _gapCursorKeymap = _interopRequireDefault(require("./pm-plugins/gap-cursor-keymap"));
|
|
14
|
-
var _commands = require("./commands");
|
|
15
|
-
var displayGapCursor = function displayGapCursor(toggle) {
|
|
16
|
-
return function (_ref) {
|
|
17
|
-
var tr = _ref.tr;
|
|
18
|
-
return tr.setMeta(_gapCursorPluginKey.gapCursorPluginKey, {
|
|
19
|
-
displayGapCursor: toggle
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref2) {
|
|
24
|
-
var options = _ref2.config;
|
|
25
|
-
return {
|
|
26
|
-
name: 'selection',
|
|
27
|
-
commands: {
|
|
28
|
-
displayGapCursor: displayGapCursor,
|
|
29
|
-
selectNearNode: _commands.selectNearNode
|
|
30
|
-
},
|
|
31
|
-
getSharedState: function getSharedState(editorState) {
|
|
32
|
-
if (!editorState) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
var pluginState = _types.selectionPluginKey.getState(editorState);
|
|
36
|
-
return {
|
|
37
|
-
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
pmPlugins: function pmPlugins() {
|
|
41
|
-
return [{
|
|
42
|
-
name: 'selection',
|
|
43
|
-
plugin: function plugin(_ref3) {
|
|
44
|
-
var dispatch = _ref3.dispatch,
|
|
45
|
-
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
|
|
46
|
-
return (0, _selectionMain.createPlugin)(dispatch, dispatchAnalyticsEvent, options);
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
name: 'selectionKeymap',
|
|
50
|
-
plugin: _keymap.default
|
|
51
|
-
}, {
|
|
52
|
-
name: 'gapCursorKeymap',
|
|
53
|
-
plugin: function plugin() {
|
|
54
|
-
return (0, _gapCursorKeymap.default)();
|
|
55
|
-
}
|
|
56
|
-
}, {
|
|
57
|
-
name: 'gapCursor',
|
|
58
|
-
plugin: function plugin() {
|
|
59
|
-
return _gapCursorMain.default;
|
|
60
|
-
}
|
|
61
|
-
}];
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
var _default = exports.default = selectionPlugin;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getPluginState = exports.createPluginState = exports.createCommand = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
|
-
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
-
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
12
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
-
var _reducer = require("./reducer");
|
|
14
|
-
var _types = require("./types");
|
|
15
|
-
var _utils2 = require("./utils");
|
|
16
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
-
var handleDocChanged = function handleDocChanged(tr, pluginState) {
|
|
19
|
-
// in some collab edge cases mapping decorations could throw an error
|
|
20
|
-
try {
|
|
21
|
-
if (pluginState.decorationSet.find().length === 0 && (!tr.selectionSet || (0, _utils2.getDecorations)(tr).find().length === 0)) {
|
|
22
|
-
return pluginState;
|
|
23
|
-
}
|
|
24
|
-
var decorationSet = pluginState.decorationSet.map(tr.mapping, tr.doc);
|
|
25
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
26
|
-
decorationSet: decorationSet
|
|
27
|
-
});
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
30
|
-
decorationSet: _view.DecorationSet.empty
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
|
|
35
|
-
// Reset relative selection pos when user clicks to select a node
|
|
36
|
-
if ((tr.selection instanceof _state.NodeSelection && (0, _utils2.isSelectableContainerNode)(tr.selection.node) || tr.selection instanceof _cellSelection.CellSelection) && !tr.getMeta(_types.selectionPluginKey)) {
|
|
37
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
38
|
-
selectionRelativeToNode: undefined
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return pluginState;
|
|
42
|
-
};
|
|
43
|
-
var _pluginFactory = (0, _utils.pluginFactory)(_types.selectionPluginKey, _reducer.reducer, {
|
|
44
|
-
onDocChanged: handleDocChanged,
|
|
45
|
-
onSelectionChanged: handleSelectionChanged
|
|
46
|
-
}),
|
|
47
|
-
createCommand = exports.createCommand = _pluginFactory.createCommand,
|
|
48
|
-
getPluginState = exports.getPluginState = _pluginFactory.getPluginState,
|
|
49
|
-
createPluginState = exports.createPluginState = _pluginFactory.createPluginState;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.onCreateSelectionBetween = void 0;
|
|
7
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
function isNodeContentEmpty(maybeNode) {
|
|
9
|
-
return (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.content.size) === 0 || (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.textContent) === '';
|
|
10
|
-
}
|
|
11
|
-
function findEmptySelectableParentNodePosition($pos, isValidPosition) {
|
|
12
|
-
var doc = $pos.doc;
|
|
13
|
-
if ($pos.pos + 1 > doc.content.size) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if ($pos.nodeBefore !== null) {
|
|
17
|
-
if (isValidPosition($pos)) {
|
|
18
|
-
return $pos;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// We can not use `$pos.before()` because ProseMirror throws an error when depth is zero.
|
|
22
|
-
var currentPosIndex = $pos.index();
|
|
23
|
-
if (currentPosIndex === 0) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
var previousIndex = currentPosIndex - 1;
|
|
27
|
-
var $previousPos = $pos.doc.resolve($pos.posAtIndex(previousIndex));
|
|
28
|
-
if (isValidPosition($previousPos)) {
|
|
29
|
-
return $previousPos;
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
if (isValidPosition($pos)) {
|
|
34
|
-
return $pos;
|
|
35
|
-
}
|
|
36
|
-
var positionLevelUp = $pos.before();
|
|
37
|
-
var resolvedPositionLevelUp = doc.resolve(positionLevelUp);
|
|
38
|
-
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp, isValidPosition);
|
|
39
|
-
}
|
|
40
|
-
var checkPositionNode = function checkPositionNode($pos) {
|
|
41
|
-
var maybeNode = $pos.nodeAfter;
|
|
42
|
-
if (!maybeNode || !maybeNode.isBlock) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (maybeNode.isAtom) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
return isNodeContentEmpty(maybeNode) && _state.NodeSelection.isSelectable(maybeNode);
|
|
49
|
-
};
|
|
50
|
-
function findNextSelectionPosition(_ref) {
|
|
51
|
-
var $targetHead = _ref.$targetHead,
|
|
52
|
-
$anchor = _ref.$anchor,
|
|
53
|
-
doc = _ref.doc;
|
|
54
|
-
var direction = $anchor.pos < $targetHead.pos ? 'down' : 'up';
|
|
55
|
-
var maybeNextPosition = findEmptySelectableParentNodePosition($targetHead, checkPositionNode);
|
|
56
|
-
if (maybeNextPosition && maybeNextPosition.nodeAfter) {
|
|
57
|
-
var nodeAfter = maybeNextPosition.nodeAfter;
|
|
58
|
-
var pos = maybeNextPosition.pos;
|
|
59
|
-
var nextPositionToSelect = direction === 'down' ? Math.min(nodeAfter.nodeSize + pos, doc.content.size) : Math.max(pos, 0);
|
|
60
|
-
return doc.resolve(nextPositionToSelect);
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
var onCreateSelectionBetween = exports.onCreateSelectionBetween = function onCreateSelectionBetween(view, $anchor, $head) {
|
|
65
|
-
var _$head$parent, _$head$parent2;
|
|
66
|
-
if ($anchor.pos === $head.pos) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
if ($anchor.depth === $head.depth && $anchor.sameParent($head)) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// If the head is targeting a paragraph on root, then let ProseMirror handle the text selection
|
|
74
|
-
if ($head.depth === 1 && ((_$head$parent = $head.parent) === null || _$head$parent === void 0 ? void 0 : _$head$parent.type.name) === 'paragraph') {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// If head is at the beginning of a non-empty textblock, let ProseMirror handle the text selection
|
|
79
|
-
if ((_$head$parent2 = $head.parent) !== null && _$head$parent2 !== void 0 && _$head$parent2.isTextblock && !isNodeContentEmpty($head.parent) && $head.parentOffset === 0) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
var $nextHeadPosition = findNextSelectionPosition({
|
|
83
|
-
$targetHead: $head,
|
|
84
|
-
$anchor: $anchor,
|
|
85
|
-
doc: view.state.doc
|
|
86
|
-
});
|
|
87
|
-
if (!$nextHeadPosition) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
var forcedTextSelection = _state.TextSelection.create(view.state.doc, $anchor.pos, $nextHeadPosition.pos);
|
|
91
|
-
return forcedTextSelection;
|
|
92
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.onKeydown = void 0;
|
|
7
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
/*
|
|
9
|
-
* The way expand was built, no browser reconize selection on it.
|
|
10
|
-
* For instance, when a selection going to a "collapsed" expand
|
|
11
|
-
* the browser will try to send the cursor to inside the expand content (wrong),
|
|
12
|
-
* this behavior is caused because the expand content is never true hidden
|
|
13
|
-
* we just set the height to 1px.
|
|
14
|
-
*
|
|
15
|
-
* So, we need to capture a possible selection event
|
|
16
|
-
* when a collapsed exxpand is the next node in the common depth.
|
|
17
|
-
* If that is true, we create a new TextSelection and stop the event bubble
|
|
18
|
-
*/
|
|
19
|
-
var isCollpasedExpand = function isCollpasedExpand(node) {
|
|
20
|
-
return Boolean(node && ['expand', 'nestedExpand'].includes(node.type.name) && !node.attrs.__expanded);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* ED-18072 - Cannot shift + arrow past bodied extension if it is not empty
|
|
25
|
-
*/
|
|
26
|
-
var isBodiedExtension = function isBodiedExtension(node) {
|
|
27
|
-
return Boolean(node && ['bodiedExtension'].includes(node.type.name));
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* ED-19861 - [Regression] keyboard selections within action items are unpredicatable
|
|
32
|
-
* Table was added to the list of problematic nodes because the desired behaviour when Shift+Up from outside the
|
|
33
|
-
* table is to select the table node itself, rather than the table cell content. Previously this behaviour was handled
|
|
34
|
-
* in `packages/editor/editor-core/src/plugins/selection/pm-plugins/events/create-selection-between.ts` but there was
|
|
35
|
-
* a bug in `create-selection-between` which after fixing the bug that code was no longer handling table selection
|
|
36
|
-
* correctly, so to fix that table was added here.
|
|
37
|
-
*/
|
|
38
|
-
var isTable = function isTable(node) {
|
|
39
|
-
return Boolean(node && ['table'].includes(node.type.name));
|
|
40
|
-
};
|
|
41
|
-
var isProblematicNode = function isProblematicNode(node) {
|
|
42
|
-
return isCollpasedExpand(node) || isBodiedExtension(node) || isTable(node);
|
|
43
|
-
};
|
|
44
|
-
var findFixedProblematicNodePosition = function findFixedProblematicNodePosition(doc, $head, direction) {
|
|
45
|
-
if ($head.pos === 0 || $head.depth === 0) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
if (direction === 'up') {
|
|
49
|
-
var pos = $head.before();
|
|
50
|
-
var $posResolved = $head.doc.resolve(pos);
|
|
51
|
-
var maybeProblematicNode = $posResolved.nodeBefore;
|
|
52
|
-
if (maybeProblematicNode && isProblematicNode(maybeProblematicNode)) {
|
|
53
|
-
var nodeSize = maybeProblematicNode.nodeSize;
|
|
54
|
-
var nodeStartPosition = pos - nodeSize;
|
|
55
|
-
|
|
56
|
-
// ($head.pos - 1) will correspond to (nodeStartPosition + nodeSize) when we are at the start of the text node
|
|
57
|
-
var isAtEndOfProblematicNode = $head.pos - 1 === nodeStartPosition + nodeSize;
|
|
58
|
-
if (isAtEndOfProblematicNode) {
|
|
59
|
-
var startPosNode = Math.max(nodeStartPosition, 0);
|
|
60
|
-
var $startPosNode = $head.doc.resolve(Math.min(startPosNode, $head.doc.content.size));
|
|
61
|
-
return $startPosNode;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (direction === 'down') {
|
|
66
|
-
var _pos = $head.after();
|
|
67
|
-
var _maybeProblematicNode = doc.nodeAt(_pos);
|
|
68
|
-
if (_maybeProblematicNode && isProblematicNode(_maybeProblematicNode) && $head.pos + 1 === _pos) {
|
|
69
|
-
var _nodeSize = _maybeProblematicNode.nodeSize;
|
|
70
|
-
var nodePosition = _pos + _nodeSize;
|
|
71
|
-
var _startPosNode = Math.max(nodePosition, 0);
|
|
72
|
-
var _$startPosNode = $head.doc.resolve(Math.min(_startPosNode, $head.doc.content.size));
|
|
73
|
-
return _$startPosNode;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
};
|
|
78
|
-
var onKeydown = exports.onKeydown = function onKeydown(view, event) {
|
|
79
|
-
/*
|
|
80
|
-
* This workaround is needed for some specific situations.
|
|
81
|
-
* - expand collapse
|
|
82
|
-
* - bodied extension
|
|
83
|
-
*/
|
|
84
|
-
if (!(event instanceof KeyboardEvent)) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
if (!event.shiftKey || event.ctrlKey || event.metaKey) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
if (!['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.key)) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
var _view$state = view.state,
|
|
94
|
-
doc = _view$state.doc,
|
|
95
|
-
_view$state$selection = _view$state.selection,
|
|
96
|
-
$head = _view$state$selection.$head,
|
|
97
|
-
$anchor = _view$state$selection.$anchor;
|
|
98
|
-
if (event.key === 'ArrowRight' && $head.nodeAfter || event.key === 'ArrowLeft' && $head.nodeBefore) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
var direction = ['ArrowLeft', 'ArrowUp', 'Home'].includes(event.key) ? 'up' : 'down';
|
|
102
|
-
var $fixedProblematicNodePosition = findFixedProblematicNodePosition(doc, $head, direction);
|
|
103
|
-
if ($fixedProblematicNodePosition) {
|
|
104
|
-
// an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
|
|
105
|
-
var headOffset = event.key === 'ArrowLeft' ? -1 : 0;
|
|
106
|
-
var head = $fixedProblematicNodePosition.pos + headOffset;
|
|
107
|
-
var forcedTextSelection = _state.TextSelection.create(view.state.doc, $anchor.pos, head);
|
|
108
|
-
var tr = view.state.tr;
|
|
109
|
-
tr.setSelection(forcedTextSelection);
|
|
110
|
-
view.dispatch(tr);
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = keymapPlugin;
|
|
7
|
-
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
8
|
-
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
9
|
-
var _actions = require("../gap-cursor/actions");
|
|
10
|
-
var _direction = require("../gap-cursor/direction");
|
|
11
|
-
var _selection = require("../gap-cursor/selection");
|
|
12
|
-
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
13
|
-
function keymapPlugin() {
|
|
14
|
-
var map = {};
|
|
15
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.insertNewLine.common, function (state, dispatch, view) {
|
|
16
|
-
var isInGapCursor = state.selection instanceof _selection.GapCursorSelection;
|
|
17
|
-
// Only operate in gap cursor
|
|
18
|
-
if (!isInGapCursor) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return (0, _commands.createParagraphNear)(state, dispatch);
|
|
22
|
-
}, map);
|
|
23
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, function (state, dispatch, view) {
|
|
24
|
-
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
|
|
25
|
-
return (0, _actions.arrow)(_direction.Direction.LEFT, endOfTextblock)(state, dispatch, view);
|
|
26
|
-
}, map);
|
|
27
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, function (state, dispatch, view) {
|
|
28
|
-
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
|
|
29
|
-
return (0, _actions.arrow)(_direction.Direction.RIGHT, endOfTextblock)(state, dispatch);
|
|
30
|
-
}, map);
|
|
31
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, function (state, dispatch, view) {
|
|
32
|
-
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
|
|
33
|
-
return (0, _actions.arrow)(_direction.Direction.UP, endOfTextblock)(state, dispatch);
|
|
34
|
-
}, map);
|
|
35
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveDown.common, function (state, dispatch, view) {
|
|
36
|
-
var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
|
|
37
|
-
return (0, _actions.arrow)(_direction.Direction.DOWN, endOfTextblock)(state, dispatch);
|
|
38
|
-
}, map);
|
|
39
|
-
|
|
40
|
-
// default PM's Backspace doesn't handle removing block nodes when cursor is after it
|
|
41
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _actions.deleteNode)(_direction.Direction.BACKWARD), map);
|
|
42
|
-
|
|
43
|
-
// handle Delete key (remove node after the cursor)
|
|
44
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, (0, _actions.deleteNode)(_direction.Direction.FORWARD), map);
|
|
45
|
-
return (0, _keymap.keymap)(map);
|
|
46
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
-
var _view2 = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
-
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
-
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
12
|
-
var _styles = require("../gap-cursor/styles");
|
|
13
|
-
var _selection = require("../gap-cursor/selection");
|
|
14
|
-
var _utils2 = require("../gap-cursor/utils");
|
|
15
|
-
var _placeGapCursor = require("../gap-cursor/utils/place-gap-cursor");
|
|
16
|
-
var _actions = require("../gap-cursor/actions");
|
|
17
|
-
var _direction = require("../gap-cursor/direction");
|
|
18
|
-
var _gapCursorPluginKey = require("./gap-cursor-plugin-key");
|
|
19
|
-
var plugin = new _safePlugin.SafePlugin({
|
|
20
|
-
key: _gapCursorPluginKey.gapCursorPluginKey,
|
|
21
|
-
state: {
|
|
22
|
-
init: function init() {
|
|
23
|
-
return {
|
|
24
|
-
selectionIsGapCursor: false,
|
|
25
|
-
displayGapCursor: true
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
apply: function apply(tr, pluginState, _oldState, newState) {
|
|
29
|
-
var _meta$displayGapCurso;
|
|
30
|
-
var meta = tr.getMeta(_gapCursorPluginKey.gapCursorPluginKey);
|
|
31
|
-
var selectionIsGapCursor = newState.selection instanceof _selection.GapCursorSelection;
|
|
32
|
-
return {
|
|
33
|
-
selectionIsGapCursor: selectionIsGapCursor,
|
|
34
|
-
// only attempt to hide gap cursor if selection is gap cursor
|
|
35
|
-
displayGapCursor: selectionIsGapCursor ? (_meta$displayGapCurso = meta === null || meta === void 0 ? void 0 : meta.displayGapCursor) !== null && _meta$displayGapCurso !== void 0 ? _meta$displayGapCurso : pluginState.displayGapCursor : true
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
view: function view(_view) {
|
|
40
|
-
/**
|
|
41
|
-
* If the selection is at the beginning of a document and is a NodeSelection,
|
|
42
|
-
* convert to a GapCursor selection. This is to stop users accidentally replacing
|
|
43
|
-
* the first node of a document by accident.
|
|
44
|
-
*/
|
|
45
|
-
if (_view.state.selection.anchor === 0 && _view.state.selection instanceof _state.NodeSelection) {
|
|
46
|
-
// This is required otherwise the dispatch doesn't trigger in the correct place
|
|
47
|
-
window.requestAnimationFrame(function () {
|
|
48
|
-
_view.dispatch(_view.state.tr.setSelection(new _selection.GapCursorSelection(_view.state.doc.resolve(0), _selection.Side.LEFT)));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
update: function update(view) {
|
|
53
|
-
var _gapCursorPluginKey$g = _gapCursorPluginKey.gapCursorPluginKey.getState(view.state),
|
|
54
|
-
selectionIsGapCursor = _gapCursorPluginKey$g.selectionIsGapCursor;
|
|
55
|
-
/**
|
|
56
|
-
* Starting with prosemirror-view 1.19.4, cursor wrapper that previously was hiding cursor doesn't exist:
|
|
57
|
-
* https://github.com/ProseMirror/prosemirror-view/commit/4a56bc7b7e61e96ef879d1dae1014ede0fc09e43
|
|
58
|
-
*
|
|
59
|
-
* Because it was causing issues with RTL: https://github.com/ProseMirror/prosemirror/issues/948
|
|
60
|
-
*
|
|
61
|
-
* This is the work around which uses `caret-color: transparent` in order to hide regular caret,
|
|
62
|
-
* when gap cursor is visible.
|
|
63
|
-
*
|
|
64
|
-
* Browser support is pretty good: https://caniuse.com/#feat=css-caret-color
|
|
65
|
-
*/
|
|
66
|
-
view.dom.classList.toggle(_styles.hideCaretModifier, selectionIsGapCursor);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
props: {
|
|
71
|
-
decorations: function decorations(editorState) {
|
|
72
|
-
var doc = editorState.doc,
|
|
73
|
-
selection = editorState.selection;
|
|
74
|
-
var _gapCursorPluginKey$g2 = _gapCursorPluginKey.gapCursorPluginKey.getState(editorState),
|
|
75
|
-
displayGapCursor = _gapCursorPluginKey$g2.displayGapCursor;
|
|
76
|
-
if (selection instanceof _selection.GapCursorSelection && displayGapCursor) {
|
|
77
|
-
var $from = selection.$from,
|
|
78
|
-
side = selection.side;
|
|
79
|
-
|
|
80
|
-
// render decoration DOM node always to the left of the target node even if selection points to the right
|
|
81
|
-
// otherwise positioning of the right gap cursor is a nightmare when the target node has a nodeView with vertical margins
|
|
82
|
-
var position = selection.head;
|
|
83
|
-
var isRightCursor = side === _selection.Side.RIGHT;
|
|
84
|
-
if (isRightCursor && $from.nodeBefore) {
|
|
85
|
-
var nodeBeforeStart = (0, _utils.findPositionOfNodeBefore)(selection);
|
|
86
|
-
if (typeof nodeBeforeStart === 'number') {
|
|
87
|
-
position = nodeBeforeStart;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
var node = isRightCursor ? $from.nodeBefore : $from.nodeAfter;
|
|
91
|
-
var layoutMode = node && (0, _utils2.getLayoutModeFromTargetNode)(node);
|
|
92
|
-
return _view2.DecorationSet.create(doc, [_view2.Decoration.widget(position, _placeGapCursor.toDOM, {
|
|
93
|
-
key: "".concat(_selection.JSON_ID, "-").concat(side, "-").concat(layoutMode),
|
|
94
|
-
side: layoutMode ? -1 : 0
|
|
95
|
-
})]);
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
},
|
|
99
|
-
// render gap cursor only when its valid
|
|
100
|
-
createSelectionBetween: function createSelectionBetween(view, $anchor, $head) {
|
|
101
|
-
if (view && view.state && view.state.selection instanceof _cellSelection.CellSelection) {
|
|
102
|
-
// Do not show GapCursor when there is a CellSection happening
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
if ($anchor.pos === $head.pos && _selection.GapCursorSelection.valid($head)) {
|
|
106
|
-
return new _selection.GapCursorSelection($head);
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
},
|
|
110
|
-
handleClick: function handleClick(view, nodePos, event) {
|
|
111
|
-
var _$pos$parent;
|
|
112
|
-
var posAtCoords = view.posAtCoords({
|
|
113
|
-
left: event.clientX,
|
|
114
|
-
top: event.clientY
|
|
115
|
-
});
|
|
116
|
-
if (!posAtCoords || (0, _utils2.isIgnoredClick)(event.target)) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
var isInsideTheTarget = posAtCoords.pos === posAtCoords.inside;
|
|
120
|
-
if (isInsideTheTarget) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
var leftSideOffsetX = 20;
|
|
124
|
-
var side = event.offsetX > leftSideOffsetX ? _selection.Side.RIGHT : _selection.Side.LEFT;
|
|
125
|
-
var $pos = view.state.doc.resolve(nodePos);
|
|
126
|
-
// In the new prosemirror-view posAtCoords is not returning a precise value for our media nodes
|
|
127
|
-
if (((_$pos$parent = $pos.parent) === null || _$pos$parent === void 0 ? void 0 : _$pos$parent.type.name) === 'mediaSingle') {
|
|
128
|
-
var $insidePos = view.state.doc.resolve(Math.max(posAtCoords.inside, 0));
|
|
129
|
-
// We don't have GapCursors problems when the node target is inside the root level
|
|
130
|
-
if ($insidePos.depth <= 1) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
var mediaGapCursor = !$pos.nodeBefore ? $pos.before() : $pos.after();
|
|
134
|
-
return (0, _actions.setGapCursorAtPos)(mediaGapCursor, side)(view.state, view.dispatch);
|
|
135
|
-
}
|
|
136
|
-
var docSize = view.state.doc.content.size;
|
|
137
|
-
var nodeInside = posAtCoords.inside < 0 || posAtCoords.inside > docSize ? null : view.state.doc.nodeAt(posAtCoords.inside);
|
|
138
|
-
if (nodeInside !== null && nodeInside !== void 0 && nodeInside.isAtom) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
return (0, _actions.setGapCursorAtPos)(nodePos, side)(view.state, view.dispatch);
|
|
142
|
-
},
|
|
143
|
-
handleDOMEvents: {
|
|
144
|
-
/**
|
|
145
|
-
* Android composition events aren't handled well by Prosemirror
|
|
146
|
-
* We've added a couple of beforeinput hooks to help PM out when trying to delete
|
|
147
|
-
* certain nodes. We can remove these when PM has better composition support.
|
|
148
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/543
|
|
149
|
-
*/
|
|
150
|
-
beforeinput: function beforeinput(view, event) {
|
|
151
|
-
if (event.inputType === 'deleteContentBackward' && view.state.selection instanceof _selection.GapCursorSelection) {
|
|
152
|
-
event.preventDefault();
|
|
153
|
-
return (0, _actions.deleteNode)(_direction.Direction.BACKWARD)(view.state, view.dispatch);
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
var _default = exports.default = plugin;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.gapCursorPluginKey = void 0;
|
|
7
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
-
var gapCursorPluginKey = exports.gapCursorPluginKey = new _state.PluginKey('gapCursorPlugin');
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
8
|
-
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
9
|
-
var _commands = require("../commands");
|
|
10
|
-
function keymapPlugin() {
|
|
11
|
-
var list = {};
|
|
12
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveRight.common, _commands.arrowRight, list);
|
|
13
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, _commands.arrowLeft, list);
|
|
14
|
-
return (0, _keymap.keymap)(list);
|
|
15
|
-
}
|
|
16
|
-
var _default = exports.default = keymapPlugin;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getInitialState = exports.createPlugin = void 0;
|
|
7
|
-
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
-
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
-
var _actions = require("../actions");
|
|
10
|
-
var _pluginFactory = require("../plugin-factory");
|
|
11
|
-
var _types = require("../types");
|
|
12
|
-
var _utils = require("../utils");
|
|
13
|
-
var _keydown = require("./events/keydown");
|
|
14
|
-
var _createSelectionBetween = require("./events/create-selection-between");
|
|
15
|
-
var getInitialState = exports.getInitialState = function getInitialState(state) {
|
|
16
|
-
return {
|
|
17
|
-
decorationSet: (0, _utils.getDecorations)(state.tr),
|
|
18
|
-
selection: state.selection
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent) {
|
|
22
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
23
|
-
return new _safePlugin.SafePlugin({
|
|
24
|
-
key: _types.selectionPluginKey,
|
|
25
|
-
state: (0, _pluginFactory.createPluginState)(dispatch, getInitialState),
|
|
26
|
-
view: function view() {
|
|
27
|
-
return {
|
|
28
|
-
update: function update(editorView, oldEditorState) {
|
|
29
|
-
var state = editorView.state;
|
|
30
|
-
if (!(0, _utils.shouldRecalcDecorations)({
|
|
31
|
-
oldEditorState: oldEditorState,
|
|
32
|
-
newEditorState: state
|
|
33
|
-
})) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
var analyticsPayload = (0, _utils.getNodeSelectionAnalyticsPayload)(state.selection) || (0, _utils.getAllSelectionAnalyticsPayload)(state.selection) ||
|
|
37
|
-
// We handle all range/cell selections except click and drag here, which is
|
|
38
|
-
// handled in mouseup handler below
|
|
39
|
-
!editorView.mouseDown && ((0, _utils.getRangeSelectionAnalyticsPayload)(state.selection, state.doc) || (0, _utils.getCellSelectionAnalyticsPayload)(state));
|
|
40
|
-
|
|
41
|
-
// We have to use dispatchAnalyticsEvent over any of the analytics plugin helpers
|
|
42
|
-
// as there were several issues caused by the fact that adding analytics through
|
|
43
|
-
// the plugin adds a new step to the transaction
|
|
44
|
-
// This causes prosemirror to run through some different code paths, eg. attempting
|
|
45
|
-
// to map selection
|
|
46
|
-
if (analyticsPayload) {
|
|
47
|
-
dispatchAnalyticsEvent(analyticsPayload);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
appendTransaction: function appendTransaction(_transactions, oldEditorState, newEditorState) {
|
|
53
|
-
if (!(0, _utils.shouldRecalcDecorations)({
|
|
54
|
-
oldEditorState: oldEditorState,
|
|
55
|
-
newEditorState: newEditorState
|
|
56
|
-
})) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
var tr = newEditorState.tr;
|
|
60
|
-
tr.setMeta(_types.selectionPluginKey, {
|
|
61
|
-
type: _actions.SelectionActionTypes.SET_DECORATIONS,
|
|
62
|
-
selection: tr.selection,
|
|
63
|
-
decorationSet: (0, _utils.getDecorations)(tr)
|
|
64
|
-
});
|
|
65
|
-
return tr;
|
|
66
|
-
},
|
|
67
|
-
filterTransaction: function filterTransaction(tr, state) {
|
|
68
|
-
// Prevent single click selecting atom nodes on mobile (we want to select with long press gesture instead)
|
|
69
|
-
if (options.useLongPressSelection && tr.selectionSet && tr.selection instanceof _state.NodeSelection && !tr.getMeta(_types.selectionPluginKey)) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Prevent prosemirror's mutation observer overriding a node selection with a text selection
|
|
74
|
-
// for exact same range - this was cause of being unable to change dates in collab:
|
|
75
|
-
// https://product-fabric.atlassian.net/browse/ED-10645
|
|
76
|
-
if (state.selection instanceof _state.NodeSelection && tr.selection instanceof _state.TextSelection && state.selection.from === tr.selection.from && state.selection.to === tr.selection.to) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
},
|
|
81
|
-
props: {
|
|
82
|
-
createSelectionBetween: _createSelectionBetween.onCreateSelectionBetween,
|
|
83
|
-
decorations: function decorations(state) {
|
|
84
|
-
return (0, _pluginFactory.getPluginState)(state).decorationSet;
|
|
85
|
-
},
|
|
86
|
-
handleDOMEvents: {
|
|
87
|
-
keydown: _keydown.onKeydown,
|
|
88
|
-
// We only want to fire analytics for a click and drag range/cell selection when
|
|
89
|
-
// the user has finished, otherwise we will get an event almost every time they move
|
|
90
|
-
// their mouse which is too much
|
|
91
|
-
mouseup: function mouseup(editorView, event) {
|
|
92
|
-
var mouseEvent = event;
|
|
93
|
-
if (!mouseEvent.shiftKey) {
|
|
94
|
-
var analyticsPayload = (0, _utils.getRangeSelectionAnalyticsPayload)(editorView.state.selection, editorView.state.doc) || (0, _utils.getCellSelectionAnalyticsPayload)(editorView.state);
|
|
95
|
-
if (analyticsPayload) {
|
|
96
|
-
dispatchAnalyticsEvent(analyticsPayload);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|