@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.
Files changed (150) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/labs/next/presets/default.js +2 -2
  3. package/dist/cjs/labs/next/presets/universal.js +1 -6
  4. package/dist/cjs/plugins/expand/index.js +0 -2
  5. package/dist/cjs/plugins/expand/nodeviews/index.js +37 -13
  6. package/dist/cjs/plugins/index.js +0 -7
  7. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +30 -29
  8. package/dist/cjs/plugins/status/actions.js +14 -11
  9. package/dist/cjs/plugins/status/index.js +17 -8
  10. package/dist/cjs/plugins/status/keymap.js +1 -1
  11. package/dist/cjs/plugins/status/ui/statusPicker.js +2 -2
  12. package/dist/cjs/ui/Addon/click-area-helper.js +9 -11
  13. package/dist/cjs/ui/ContentStyles/index.js +13 -13
  14. package/dist/cjs/utils/selection.js +12 -14
  15. package/dist/cjs/version-wrapper.js +1 -1
  16. package/dist/es2019/labs/next/presets/default.js +1 -1
  17. package/dist/es2019/labs/next/presets/universal.js +1 -6
  18. package/dist/es2019/plugins/expand/index.js +0 -2
  19. package/dist/es2019/plugins/expand/nodeviews/index.js +37 -13
  20. package/dist/es2019/plugins/index.js +0 -1
  21. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +3 -3
  22. package/dist/es2019/plugins/status/actions.js +3 -2
  23. package/dist/es2019/plugins/status/index.js +91 -80
  24. package/dist/es2019/plugins/status/keymap.js +1 -1
  25. package/dist/es2019/plugins/status/ui/statusPicker.js +1 -1
  26. package/dist/es2019/ui/Addon/click-area-helper.js +4 -6
  27. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  28. package/dist/es2019/utils/selection.js +2 -17
  29. package/dist/es2019/version-wrapper.js +1 -1
  30. package/dist/esm/labs/next/presets/default.js +1 -1
  31. package/dist/esm/labs/next/presets/universal.js +1 -6
  32. package/dist/esm/plugins/expand/index.js +0 -2
  33. package/dist/esm/plugins/expand/nodeviews/index.js +37 -13
  34. package/dist/esm/plugins/index.js +0 -1
  35. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +30 -29
  36. package/dist/esm/plugins/status/actions.js +14 -11
  37. package/dist/esm/plugins/status/index.js +17 -8
  38. package/dist/esm/plugins/status/keymap.js +1 -1
  39. package/dist/esm/plugins/status/ui/statusPicker.js +1 -1
  40. package/dist/esm/ui/Addon/click-area-helper.js +4 -6
  41. package/dist/esm/ui/ContentStyles/index.js +1 -1
  42. package/dist/esm/utils/selection.js +2 -13
  43. package/dist/esm/version-wrapper.js +1 -1
  44. package/dist/types/labs/next/presets/default.d.ts +22 -8
  45. package/dist/types/plugins/expand/index.d.ts +1 -1
  46. package/dist/types/plugins/expand/nodeviews/index.d.ts +3 -2
  47. package/dist/types/plugins/index.d.ts +0 -1
  48. package/dist/types/plugins/insert-block/types.d.ts +3 -1
  49. package/dist/types/plugins/status/actions.d.ts +4 -2
  50. package/dist/types/plugins/status/index.d.ts +12 -3
  51. package/dist/types/plugins/status/nodeviews/status.d.ts +1 -1
  52. package/dist/types/plugins/status/plugin.d.ts +1 -1
  53. package/dist/types/utils/selection.d.ts +1 -4
  54. package/package.json +4 -3
  55. package/dist/cjs/plugins/selection/actions.js +0 -11
  56. package/dist/cjs/plugins/selection/commands.js +0 -257
  57. package/dist/cjs/plugins/selection/gap-cursor/actions.js +0 -272
  58. package/dist/cjs/plugins/selection/gap-cursor/direction.js +0 -23
  59. package/dist/cjs/plugins/selection/gap-cursor/selection.js +0 -30
  60. package/dist/cjs/plugins/selection/gap-cursor/styles.js +0 -17
  61. package/dist/cjs/plugins/selection/gap-cursor/utils/is-ignored.js +0 -12
  62. package/dist/cjs/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -12
  63. package/dist/cjs/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -103
  64. package/dist/cjs/plugins/selection/gap-cursor/utils.js +0 -137
  65. package/dist/cjs/plugins/selection/gap-cursor-selection.js +0 -37
  66. package/dist/cjs/plugins/selection/index.js +0 -65
  67. package/dist/cjs/plugins/selection/plugin-factory.js +0 -49
  68. package/dist/cjs/plugins/selection/pm-plugins/events/create-selection-between.js +0 -92
  69. package/dist/cjs/plugins/selection/pm-plugins/events/keydown.js +0 -115
  70. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -46
  71. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-main.js +0 -160
  72. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -8
  73. package/dist/cjs/plugins/selection/pm-plugins/keymap.js +0 -16
  74. package/dist/cjs/plugins/selection/pm-plugins/selection-main.js +0 -104
  75. package/dist/cjs/plugins/selection/reducer.js +0 -26
  76. package/dist/cjs/plugins/selection/types.js +0 -20
  77. package/dist/cjs/plugins/selection/utils.js +0 -280
  78. package/dist/cjs/selection-api/api.js +0 -27
  79. package/dist/es2019/plugins/selection/actions.js +0 -5
  80. package/dist/es2019/plugins/selection/commands.js +0 -250
  81. package/dist/es2019/plugins/selection/gap-cursor/actions.js +0 -270
  82. package/dist/es2019/plugins/selection/gap-cursor/direction.js +0 -15
  83. package/dist/es2019/plugins/selection/gap-cursor/selection.js +0 -1
  84. package/dist/es2019/plugins/selection/gap-cursor/styles.js +0 -145
  85. package/dist/es2019/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
  86. package/dist/es2019/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
  87. package/dist/es2019/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -94
  88. package/dist/es2019/plugins/selection/gap-cursor/utils.js +0 -124
  89. package/dist/es2019/plugins/selection/gap-cursor-selection.js +0 -2
  90. package/dist/es2019/plugins/selection/index.js +0 -51
  91. package/dist/es2019/plugins/selection/plugin-factory.js +0 -43
  92. package/dist/es2019/plugins/selection/pm-plugins/events/create-selection-between.js +0 -89
  93. package/dist/es2019/plugins/selection/pm-plugins/events/keydown.js +0 -112
  94. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
  95. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-main.js +0 -158
  96. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
  97. package/dist/es2019/plugins/selection/pm-plugins/keymap.js +0 -10
  98. package/dist/es2019/plugins/selection/pm-plugins/selection-main.js +0 -97
  99. package/dist/es2019/plugins/selection/reducer.js +0 -18
  100. package/dist/es2019/plugins/selection/types.js +0 -9
  101. package/dist/es2019/plugins/selection/utils.js +0 -233
  102. package/dist/es2019/selection-api/api.js +0 -20
  103. package/dist/esm/plugins/selection/actions.js +0 -5
  104. package/dist/esm/plugins/selection/commands.js +0 -251
  105. package/dist/esm/plugins/selection/gap-cursor/actions.js +0 -266
  106. package/dist/esm/plugins/selection/gap-cursor/direction.js +0 -15
  107. package/dist/esm/plugins/selection/gap-cursor/selection.js +0 -1
  108. package/dist/esm/plugins/selection/gap-cursor/styles.js +0 -10
  109. package/dist/esm/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
  110. package/dist/esm/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
  111. package/dist/esm/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -97
  112. package/dist/esm/plugins/selection/gap-cursor/utils.js +0 -128
  113. package/dist/esm/plugins/selection/gap-cursor-selection.js +0 -2
  114. package/dist/esm/plugins/selection/index.js +0 -58
  115. package/dist/esm/plugins/selection/plugin-factory.js +0 -43
  116. package/dist/esm/plugins/selection/pm-plugins/events/create-selection-between.js +0 -86
  117. package/dist/esm/plugins/selection/pm-plugins/events/keydown.js +0 -110
  118. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
  119. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-main.js +0 -154
  120. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
  121. package/dist/esm/plugins/selection/pm-plugins/keymap.js +0 -10
  122. package/dist/esm/plugins/selection/pm-plugins/selection-main.js +0 -98
  123. package/dist/esm/plugins/selection/reducer.js +0 -19
  124. package/dist/esm/plugins/selection/types.js +0 -9
  125. package/dist/esm/plugins/selection/utils.js +0 -241
  126. package/dist/esm/selection-api/api.js +0 -21
  127. package/dist/types/plugins/selection/actions.d.ts +0 -17
  128. package/dist/types/plugins/selection/commands.d.ts +0 -10
  129. package/dist/types/plugins/selection/gap-cursor/actions.d.ts +0 -25
  130. package/dist/types/plugins/selection/gap-cursor/direction.d.ts +0 -10
  131. package/dist/types/plugins/selection/gap-cursor/selection.d.ts +0 -1
  132. package/dist/types/plugins/selection/gap-cursor/styles.d.ts +0 -2
  133. package/dist/types/plugins/selection/gap-cursor/utils/is-ignored.d.ts +0 -1
  134. package/dist/types/plugins/selection/gap-cursor/utils/is-valid-target-node.d.ts +0 -1
  135. package/dist/types/plugins/selection/gap-cursor/utils/place-gap-cursor.d.ts +0 -2
  136. package/dist/types/plugins/selection/gap-cursor/utils.d.ts +0 -8
  137. package/dist/types/plugins/selection/gap-cursor-selection.d.ts +0 -2
  138. package/dist/types/plugins/selection/index.d.ts +0 -13
  139. package/dist/types/plugins/selection/plugin-factory.d.ts +0 -2
  140. package/dist/types/plugins/selection/pm-plugins/events/create-selection-between.d.ts +0 -4
  141. package/dist/types/plugins/selection/pm-plugins/events/keydown.d.ts +0 -2
  142. package/dist/types/plugins/selection/pm-plugins/gap-cursor-keymap.d.ts +0 -2
  143. package/dist/types/plugins/selection/pm-plugins/gap-cursor-main.d.ts +0 -6
  144. package/dist/types/plugins/selection/pm-plugins/gap-cursor-plugin-key.d.ts +0 -2
  145. package/dist/types/plugins/selection/pm-plugins/keymap.d.ts +0 -3
  146. package/dist/types/plugins/selection/pm-plugins/selection-main.d.ts +0 -7
  147. package/dist/types/plugins/selection/reducer.d.ts +0 -3
  148. package/dist/types/plugins/selection/types.d.ts +0 -12
  149. package/dist/types/plugins/selection/utils.d.ts +0 -58
  150. package/dist/types/selection-api/api.d.ts +0 -11
@@ -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
- };
@@ -1,26 +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.reducer = reducer;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _actions = require("./actions");
10
- 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; }
11
- 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; }
12
- function reducer(pluginState, action) {
13
- switch (action.type) {
14
- case _actions.SelectionActionTypes.SET_DECORATIONS:
15
- return _objectSpread(_objectSpread({}, pluginState), {}, {
16
- decorationSet: action.decorationSet,
17
- selection: action.selection
18
- });
19
- case _actions.SelectionActionTypes.SET_RELATIVE_SELECTION:
20
- return _objectSpread(_objectSpread({}, pluginState), {}, {
21
- selectionRelativeToNode: action.selectionRelativeToNode
22
- });
23
- default:
24
- return pluginState;
25
- }
26
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "RelativeSelectionPos", {
7
- enumerable: true,
8
- get: function get() {
9
- return _selection.RelativeSelectionPos;
10
- }
11
- });
12
- exports.selectionPluginKey = exports.SelectionDirection = void 0;
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var _selection = require("@atlaskit/editor-common/selection");
15
- var selectionPluginKey = exports.selectionPluginKey = new _state.PluginKey('selection');
16
- var SelectionDirection = exports.SelectionDirection = /*#__PURE__*/function (SelectionDirection) {
17
- SelectionDirection[SelectionDirection["Before"] = -1] = "Before";
18
- SelectionDirection[SelectionDirection["After"] = 1] = "After";
19
- return SelectionDirection;
20
- }({});
@@ -1,280 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "createSelectionClickHandler", {
7
- enumerable: true,
8
- get: function get() {
9
- return _selection.createSelectionClickHandler;
10
- }
11
- });
12
- exports.findSelectableContainerParent = exports.findSelectableContainerBefore = exports.findSelectableContainerAfter = exports.findLastChildNodeToSelect = exports.findFirstChildNodeToSelect = void 0;
13
- Object.defineProperty(exports, "getAllSelectionAnalyticsPayload", {
14
- enumerable: true,
15
- get: function get() {
16
- return _selection.getAllSelectionAnalyticsPayload;
17
- }
18
- });
19
- Object.defineProperty(exports, "getCellSelectionAnalyticsPayload", {
20
- enumerable: true,
21
- get: function get() {
22
- return _selection.getCellSelectionAnalyticsPayload;
23
- }
24
- });
25
- exports.getDecorations = void 0;
26
- Object.defineProperty(exports, "getNodeSelectionAnalyticsPayload", {
27
- enumerable: true,
28
- get: function get() {
29
- return _selection.getNodeSelectionAnalyticsPayload;
30
- }
31
- });
32
- exports.getNodesToDecorateFromSelection = void 0;
33
- Object.defineProperty(exports, "getRangeSelectionAnalyticsPayload", {
34
- enumerable: true,
35
- get: function get() {
36
- return _selection.getRangeSelectionAnalyticsPayload;
37
- }
38
- });
39
- exports.isSelectionAtStartOfParentNode = exports.isSelectionAtEndOfParentNode = exports.isSelectableContainerNode = exports.isSelectableChildNode = void 0;
40
- exports.shouldRecalcDecorations = shouldRecalcDecorations;
41
- var _state = require("@atlaskit/editor-prosemirror/state");
42
- var _view = require("@atlaskit/editor-prosemirror/view");
43
- var _utils = require("@atlaskit/editor-prosemirror/utils");
44
- var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
45
- var _selection = require("@atlaskit/editor-common/selection");
46
- var _utils2 = require("@atlaskit/editor-common/utils");
47
- var _types = require("./types");
48
- var getDecorations = exports.getDecorations = function getDecorations(tr) {
49
- if (tr.selection instanceof _state.NodeSelection) {
50
- return _view.DecorationSet.create(tr.doc, [_view.Decoration.node(tr.selection.from, tr.selection.to, {
51
- class: _editorSharedStyles.akEditorSelectedNodeClassName
52
- })]);
53
- }
54
- if (tr.selection instanceof _state.TextSelection || tr.selection instanceof _state.AllSelection) {
55
- var decorations = getNodesToDecorateFromSelection(tr.selection, tr.doc).map(function (_ref) {
56
- var node = _ref.node,
57
- pos = _ref.pos;
58
- return _view.Decoration.node(pos, pos + node.nodeSize, {
59
- class: _editorSharedStyles.akEditorSelectedNodeClassName
60
- });
61
- });
62
- return _view.DecorationSet.create(tr.doc, decorations);
63
- }
64
- return _view.DecorationSet.empty;
65
- };
66
- var topLevelBlockNodesThatHaveSelectionStyles = ['table', 'panel', 'expand', 'layoutSection', 'decisionList', 'decisionItem', 'codeBlock'];
67
-
68
- /**
69
- * Use `getNodesToDecorateFromSelection` to collect and return
70
- * a list of nodes within the Selection that should have Selection
71
- * decorations applied. This allows selection styles to be added to
72
- * nested nodes. It will ignore text nodes as decorations are
73
- * applied natively and also ignore nodes that don't completely
74
- * sit within the given `Selection`.
75
- */
76
- var getNodesToDecorateFromSelection = exports.getNodesToDecorateFromSelection = function getNodesToDecorateFromSelection(selection, doc) {
77
- var nodes = [];
78
- if (selection.from !== selection.to) {
79
- var from = selection.from,
80
- to = selection.to;
81
- doc.nodesBetween(from, to, function (node, pos) {
82
- var withinSelection = from <= pos && pos + node.nodeSize <= to;
83
- // The reason we need to check for these nodes is to stop
84
- // traversing their children if they are within a selection -
85
- // this is to prevent selection styles from being added to
86
- // the children as well as the parent node.
87
- // Example scenario is if an entire table has been selected
88
- // we should not traverse its children so we can apply the
89
- // selection styles to the table. But if an entire tableRow
90
- // has been selected (but the parent table has not) we should
91
- // traverse it as it could contain other nodes that need
92
- // selection styles. I couldn’t see a clear way to differentiate
93
- // without explicitly stating which nodes should be traversed
94
- // and which shouldn’t.
95
- var isTopLevelNodeThatHasSelectionStyles = topLevelBlockNodesThatHaveSelectionStyles.includes(node.type.name);
96
- // If the node is a top-level block node and completely sits within
97
- // the selection, we do not recurse it's children to prevent selection
98
- // styles being added to its child nodes. The expected behaviour
99
- // is that selection styles are only added to the parent.
100
- if (node && withinSelection && isTopLevelNodeThatHasSelectionStyles) {
101
- nodes.push({
102
- node: node,
103
- pos: pos
104
- });
105
- return false;
106
- // Otherwise we recurse the children and return them so we can apply
107
- // selection styles. Text is handled by the browser.
108
- } else if (node && withinSelection && !node.isText) {
109
- nodes.push({
110
- node: node,
111
- pos: pos
112
- });
113
- }
114
- return true;
115
- });
116
- }
117
- return nodes;
118
- };
119
- function shouldRecalcDecorations(_ref2) {
120
- var oldEditorState = _ref2.oldEditorState,
121
- newEditorState = _ref2.newEditorState;
122
- var oldSelection = oldEditorState.selection;
123
- var newSelection = newEditorState.selection;
124
- var oldPluginState = _types.selectionPluginKey.getState(oldEditorState);
125
- var newPluginState = _types.selectionPluginKey.getState(newEditorState);
126
- if (!oldPluginState || !newPluginState) {
127
- return false;
128
- }
129
-
130
- // If selection is unchanged, no need to recalculate
131
- if (oldSelection.eq(newSelection)) {
132
- // We need this special case for NodeSelection, as Prosemirror still thinks the
133
- // selections are equal when the node has changed
134
- if (oldSelection instanceof _state.NodeSelection && newSelection instanceof _state.NodeSelection) {
135
- var oldDecorations = oldPluginState.decorationSet.find();
136
- var newDecorations = newPluginState.decorationSet.find();
137
- // There might not be old or new decorations if the node selection is for a text node
138
- // This wouldn't have happened intentionally, but we need to handle this case regardless
139
- if (oldDecorations.length > 0 && newDecorations.length > 0) {
140
- return !oldDecorations[0].eq(newDecorations[0]);
141
- }
142
- return !(oldDecorations.length === 0 && newDecorations.length === 0);
143
- }
144
- return false;
145
- }
146
-
147
- // There's no point updating decorations if going from one standard TextSelection to another
148
- if (oldSelection instanceof _state.TextSelection && newSelection instanceof _state.TextSelection && oldSelection.from === oldSelection.to && newSelection.from === newSelection.to) {
149
- return false;
150
- }
151
- return true;
152
- }
153
- var isSelectableContainerNode = exports.isSelectableContainerNode = function isSelectableContainerNode(node) {
154
- return !!(node && !node.isAtom && _state.NodeSelection.isSelectable(node));
155
- };
156
- var isSelectableChildNode = exports.isSelectableChildNode = function isSelectableChildNode(node) {
157
- return !!(node && (node.isText || (0, _utils2.isEmptyParagraph)(node) || _state.NodeSelection.isSelectable(node)));
158
- };
159
-
160
- /**
161
- * Finds closest parent node that is a selectable block container node
162
- * If it finds a parent that is not selectable but supports gap cursor, will
163
- * return undefined
164
- */
165
- var findSelectableContainerParent = exports.findSelectableContainerParent = function findSelectableContainerParent(selection) {
166
- var foundNodeThatSupportsGapCursor = false;
167
- var selectableNode = (0, _utils.findParentNode)(function (node) {
168
- var isSelectable = isSelectableContainerNode(node);
169
- if (!isSelectable && !(0, _selection.isIgnored)(node)) {
170
- foundNodeThatSupportsGapCursor = true;
171
- }
172
- return isSelectable;
173
- })(selection);
174
- if (!foundNodeThatSupportsGapCursor) {
175
- return selectableNode;
176
- }
177
- };
178
-
179
- /**
180
- * Finds node before that is a selectable block container node, starting
181
- * from $pos.depth + 1 and working in
182
- * If it finds a node that is not selectable but supports gap cursor, will
183
- * return undefined
184
- */
185
- var findSelectableContainerBefore = exports.findSelectableContainerBefore = function findSelectableContainerBefore($pos, doc) {
186
- // prosemirror just returns the same pos from Selection.findFrom when
187
- // parent.inlineContent is true, so we move position back one here
188
- // to counteract that
189
- if ($pos.parent.inlineContent && isSelectableContainerNode($pos.parent)) {
190
- $pos = doc.resolve($pos.start() - 1);
191
- }
192
- var selectionBefore = _state.Selection.findFrom($pos, -1);
193
- if (selectionBefore) {
194
- var $selectionBefore = doc.resolve(selectionBefore.from);
195
- for (var i = $pos.depth + 1; i <= $selectionBefore.depth; i++) {
196
- var node = $selectionBefore.node(i);
197
- if (isSelectableContainerNode(node)) {
198
- return {
199
- node: node,
200
- pos: $selectionBefore.start(i) - 1
201
- };
202
- }
203
- if (i > $pos.depth + 1 && !(0, _selection.isIgnored)(node)) {
204
- return;
205
- }
206
- }
207
-
208
- /**
209
- * Stick to the default left selection behaviour,
210
- * useful for mediaSingleWithCaption
211
- */
212
- if (selectionBefore instanceof _state.NodeSelection && _state.NodeSelection.isSelectable(selectionBefore.node)) {
213
- return {
214
- node: selectionBefore.node,
215
- pos: selectionBefore.from
216
- };
217
- }
218
- }
219
- };
220
-
221
- /**
222
- * Finds node after that is a selectable block container node, starting
223
- * from $pos.depth + 1 and working in
224
- * If it finds a node that is not selectable but supports gap cursor, will
225
- * return undefined
226
- */
227
- var findSelectableContainerAfter = exports.findSelectableContainerAfter = function findSelectableContainerAfter($pos, doc) {
228
- var selectionAfter = _state.Selection.findFrom($pos, 1);
229
- if (selectionAfter) {
230
- var $selectionAfter = doc.resolve(selectionAfter.from);
231
- for (var i = $pos.depth + 1; i <= $selectionAfter.depth; i++) {
232
- var node = $selectionAfter.node(i);
233
- if (isSelectableContainerNode(node)) {
234
- return {
235
- node: node,
236
- pos: $selectionAfter.start(i) - 1
237
- };
238
- }
239
- if (i > $pos.depth + 1 && !(0, _selection.isIgnored)(node)) {
240
- return;
241
- }
242
- }
243
- }
244
- };
245
-
246
- /**
247
- * Finds first child node that is a selectable block container node OR that
248
- * supports gap cursor
249
- */
250
- var findFirstChildNodeToSelect = exports.findFirstChildNodeToSelect = function findFirstChildNodeToSelect(parent) {
251
- return (0, _utils.flatten)(parent).find(function (child) {
252
- return isSelectableChildNode(child.node) || !(0, _selection.isIgnored)(child.node);
253
- });
254
- };
255
-
256
- /**
257
- * Finds last child node that is a selectable block container node OR that
258
- * supports gap cursor
259
- */
260
- var findLastChildNodeToSelect = exports.findLastChildNodeToSelect = function findLastChildNodeToSelect(parent) {
261
- var child;
262
- parent.descendants(function (node, pos) {
263
- if (isSelectableChildNode(node) || !(0, _selection.isIgnored)(node)) {
264
- child = {
265
- node: node,
266
- pos: pos
267
- };
268
- return false;
269
- }
270
- });
271
- if (child) {
272
- return child;
273
- }
274
- };
275
- var isSelectionAtStartOfParentNode = exports.isSelectionAtStartOfParentNode = function isSelectionAtStartOfParentNode($pos, selection) {
276
- return (0, _selection.isSelectionAtStartOfNode)($pos, findSelectableContainerParent(selection));
277
- };
278
- var isSelectionAtEndOfParentNode = exports.isSelectionAtEndOfParentNode = function isSelectionAtEndOfParentNode($pos, selection) {
279
- return (0, _selection.isSelectionAtEndOfNode)($pos, findSelectableContainerParent(selection));
280
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createEditorSelectionAPI = void 0;
7
- var _commands = require("../plugins/selection/commands");
8
- var _pluginFactory = require("../plugins/selection/plugin-factory");
9
- var createEditorSelectionAPI = exports.createEditorSelectionAPI = function createEditorSelectionAPI() {
10
- return {
11
- getSelectionPluginState: function getSelectionPluginState(state) {
12
- return (0, _pluginFactory.getPluginState)(state);
13
- },
14
- setSelectionRelativeToNode: function setSelectionRelativeToNode(_ref) {
15
- var selectionRelativeToNode = _ref.selectionRelativeToNode,
16
- selection = _ref.selection;
17
- return function (state) {
18
- var tr = state.tr;
19
- var fakeDispatch = function fakeDispatch(_tr) {
20
- tr = _tr;
21
- };
22
- (0, _commands.setSelectionRelativeToNode)(selectionRelativeToNode, selection)(state, fakeDispatch);
23
- return tr;
24
- };
25
- }
26
- };
27
- };
@@ -1,5 +0,0 @@
1
- export let SelectionActionTypes = /*#__PURE__*/function (SelectionActionTypes) {
2
- SelectionActionTypes["SET_DECORATIONS"] = "SET_DECORATIONS";
3
- SelectionActionTypes["SET_RELATIVE_SELECTION"] = "SET_RELATIVE_SELECTION";
4
- return SelectionActionTypes;
5
- }({});