@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.
Files changed (130) hide show
  1. package/CHANGELOG.md +7 -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/ui/Addon/click-area-helper.js +9 -11
  8. package/dist/cjs/ui/ContentStyles/index.js +13 -13
  9. package/dist/cjs/utils/selection.js +12 -14
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/es2019/labs/next/presets/default.js +1 -1
  12. package/dist/es2019/labs/next/presets/universal.js +1 -6
  13. package/dist/es2019/plugins/expand/index.js +0 -2
  14. package/dist/es2019/plugins/expand/nodeviews/index.js +37 -13
  15. package/dist/es2019/plugins/index.js +0 -1
  16. package/dist/es2019/ui/Addon/click-area-helper.js +4 -6
  17. package/dist/es2019/ui/ContentStyles/index.js +1 -1
  18. package/dist/es2019/utils/selection.js +2 -17
  19. package/dist/es2019/version-wrapper.js +1 -1
  20. package/dist/esm/labs/next/presets/default.js +1 -1
  21. package/dist/esm/labs/next/presets/universal.js +1 -6
  22. package/dist/esm/plugins/expand/index.js +0 -2
  23. package/dist/esm/plugins/expand/nodeviews/index.js +37 -13
  24. package/dist/esm/plugins/index.js +0 -1
  25. package/dist/esm/ui/Addon/click-area-helper.js +4 -6
  26. package/dist/esm/ui/ContentStyles/index.js +1 -1
  27. package/dist/esm/utils/selection.js +2 -13
  28. package/dist/esm/version-wrapper.js +1 -1
  29. package/dist/types/labs/next/presets/default.d.ts +22 -8
  30. package/dist/types/plugins/expand/index.d.ts +1 -1
  31. package/dist/types/plugins/expand/nodeviews/index.d.ts +3 -2
  32. package/dist/types/plugins/index.d.ts +0 -1
  33. package/dist/types/utils/selection.d.ts +1 -4
  34. package/package.json +4 -3
  35. package/dist/cjs/plugins/selection/actions.js +0 -11
  36. package/dist/cjs/plugins/selection/commands.js +0 -257
  37. package/dist/cjs/plugins/selection/gap-cursor/actions.js +0 -272
  38. package/dist/cjs/plugins/selection/gap-cursor/direction.js +0 -23
  39. package/dist/cjs/plugins/selection/gap-cursor/selection.js +0 -30
  40. package/dist/cjs/plugins/selection/gap-cursor/styles.js +0 -17
  41. package/dist/cjs/plugins/selection/gap-cursor/utils/is-ignored.js +0 -12
  42. package/dist/cjs/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -12
  43. package/dist/cjs/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -103
  44. package/dist/cjs/plugins/selection/gap-cursor/utils.js +0 -137
  45. package/dist/cjs/plugins/selection/gap-cursor-selection.js +0 -37
  46. package/dist/cjs/plugins/selection/index.js +0 -65
  47. package/dist/cjs/plugins/selection/plugin-factory.js +0 -49
  48. package/dist/cjs/plugins/selection/pm-plugins/events/create-selection-between.js +0 -92
  49. package/dist/cjs/plugins/selection/pm-plugins/events/keydown.js +0 -115
  50. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -46
  51. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-main.js +0 -160
  52. package/dist/cjs/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -8
  53. package/dist/cjs/plugins/selection/pm-plugins/keymap.js +0 -16
  54. package/dist/cjs/plugins/selection/pm-plugins/selection-main.js +0 -104
  55. package/dist/cjs/plugins/selection/reducer.js +0 -26
  56. package/dist/cjs/plugins/selection/types.js +0 -20
  57. package/dist/cjs/plugins/selection/utils.js +0 -280
  58. package/dist/cjs/selection-api/api.js +0 -27
  59. package/dist/es2019/plugins/selection/actions.js +0 -5
  60. package/dist/es2019/plugins/selection/commands.js +0 -250
  61. package/dist/es2019/plugins/selection/gap-cursor/actions.js +0 -270
  62. package/dist/es2019/plugins/selection/gap-cursor/direction.js +0 -15
  63. package/dist/es2019/plugins/selection/gap-cursor/selection.js +0 -1
  64. package/dist/es2019/plugins/selection/gap-cursor/styles.js +0 -145
  65. package/dist/es2019/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
  66. package/dist/es2019/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
  67. package/dist/es2019/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -94
  68. package/dist/es2019/plugins/selection/gap-cursor/utils.js +0 -124
  69. package/dist/es2019/plugins/selection/gap-cursor-selection.js +0 -2
  70. package/dist/es2019/plugins/selection/index.js +0 -51
  71. package/dist/es2019/plugins/selection/plugin-factory.js +0 -43
  72. package/dist/es2019/plugins/selection/pm-plugins/events/create-selection-between.js +0 -89
  73. package/dist/es2019/plugins/selection/pm-plugins/events/keydown.js +0 -112
  74. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
  75. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-main.js +0 -158
  76. package/dist/es2019/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
  77. package/dist/es2019/plugins/selection/pm-plugins/keymap.js +0 -10
  78. package/dist/es2019/plugins/selection/pm-plugins/selection-main.js +0 -97
  79. package/dist/es2019/plugins/selection/reducer.js +0 -18
  80. package/dist/es2019/plugins/selection/types.js +0 -9
  81. package/dist/es2019/plugins/selection/utils.js +0 -233
  82. package/dist/es2019/selection-api/api.js +0 -20
  83. package/dist/esm/plugins/selection/actions.js +0 -5
  84. package/dist/esm/plugins/selection/commands.js +0 -251
  85. package/dist/esm/plugins/selection/gap-cursor/actions.js +0 -266
  86. package/dist/esm/plugins/selection/gap-cursor/direction.js +0 -15
  87. package/dist/esm/plugins/selection/gap-cursor/selection.js +0 -1
  88. package/dist/esm/plugins/selection/gap-cursor/styles.js +0 -10
  89. package/dist/esm/plugins/selection/gap-cursor/utils/is-ignored.js +0 -1
  90. package/dist/esm/plugins/selection/gap-cursor/utils/is-valid-target-node.js +0 -1
  91. package/dist/esm/plugins/selection/gap-cursor/utils/place-gap-cursor.js +0 -97
  92. package/dist/esm/plugins/selection/gap-cursor/utils.js +0 -128
  93. package/dist/esm/plugins/selection/gap-cursor-selection.js +0 -2
  94. package/dist/esm/plugins/selection/index.js +0 -58
  95. package/dist/esm/plugins/selection/plugin-factory.js +0 -43
  96. package/dist/esm/plugins/selection/pm-plugins/events/create-selection-between.js +0 -86
  97. package/dist/esm/plugins/selection/pm-plugins/events/keydown.js +0 -110
  98. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-keymap.js +0 -40
  99. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-main.js +0 -154
  100. package/dist/esm/plugins/selection/pm-plugins/gap-cursor-plugin-key.js +0 -2
  101. package/dist/esm/plugins/selection/pm-plugins/keymap.js +0 -10
  102. package/dist/esm/plugins/selection/pm-plugins/selection-main.js +0 -98
  103. package/dist/esm/plugins/selection/reducer.js +0 -19
  104. package/dist/esm/plugins/selection/types.js +0 -9
  105. package/dist/esm/plugins/selection/utils.js +0 -241
  106. package/dist/esm/selection-api/api.js +0 -21
  107. package/dist/types/plugins/selection/actions.d.ts +0 -17
  108. package/dist/types/plugins/selection/commands.d.ts +0 -10
  109. package/dist/types/plugins/selection/gap-cursor/actions.d.ts +0 -25
  110. package/dist/types/plugins/selection/gap-cursor/direction.d.ts +0 -10
  111. package/dist/types/plugins/selection/gap-cursor/selection.d.ts +0 -1
  112. package/dist/types/plugins/selection/gap-cursor/styles.d.ts +0 -2
  113. package/dist/types/plugins/selection/gap-cursor/utils/is-ignored.d.ts +0 -1
  114. package/dist/types/plugins/selection/gap-cursor/utils/is-valid-target-node.d.ts +0 -1
  115. package/dist/types/plugins/selection/gap-cursor/utils/place-gap-cursor.d.ts +0 -2
  116. package/dist/types/plugins/selection/gap-cursor/utils.d.ts +0 -8
  117. package/dist/types/plugins/selection/gap-cursor-selection.d.ts +0 -2
  118. package/dist/types/plugins/selection/index.d.ts +0 -13
  119. package/dist/types/plugins/selection/plugin-factory.d.ts +0 -2
  120. package/dist/types/plugins/selection/pm-plugins/events/create-selection-between.d.ts +0 -4
  121. package/dist/types/plugins/selection/pm-plugins/events/keydown.d.ts +0 -2
  122. package/dist/types/plugins/selection/pm-plugins/gap-cursor-keymap.d.ts +0 -2
  123. package/dist/types/plugins/selection/pm-plugins/gap-cursor-main.d.ts +0 -6
  124. package/dist/types/plugins/selection/pm-plugins/gap-cursor-plugin-key.d.ts +0 -2
  125. package/dist/types/plugins/selection/pm-plugins/keymap.d.ts +0 -3
  126. package/dist/types/plugins/selection/pm-plugins/selection-main.d.ts +0 -7
  127. package/dist/types/plugins/selection/reducer.d.ts +0 -3
  128. package/dist/types/plugins/selection/types.d.ts +0 -12
  129. package/dist/types/plugins/selection/utils.d.ts +0 -58
  130. package/dist/types/selection-api/api.d.ts +0 -11
@@ -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
- }({});
@@ -1,250 +0,0 @@
1
- import { NodeSelection, TextSelection, Selection } from '@atlaskit/editor-prosemirror/state';
2
- import { GapCursorSelection, Side } from './gap-cursor-selection';
3
- import { isIgnored as isIgnoredByGapCursor } from '@atlaskit/editor-common/selection';
4
- import { isNodeEmpty, isEmptyParagraph } from '@atlaskit/editor-common/utils';
5
- import { SelectionActionTypes } from './actions';
6
- import { createCommand, getPluginState } from './plugin-factory';
7
- import { isSelectableContainerNode, isSelectionAtEndOfParentNode, findSelectableContainerParent, isSelectionAtStartOfParentNode, findSelectableContainerBefore, findSelectableContainerAfter, findFirstChildNodeToSelect, findLastChildNodeToSelect } from './utils';
8
- import { RelativeSelectionPos, SelectionDirection, selectionPluginKey } from './types';
9
- export const selectNearNode = (selectionRelativeToNode, selection) => ({
10
- tr
11
- }) => {
12
- tr.setMeta(selectionPluginKey, {
13
- type: SelectionActionTypes.SET_RELATIVE_SELECTION,
14
- selectionRelativeToNode
15
- });
16
- if (selection) {
17
- return tr.setSelection(selection);
18
- }
19
- return tr;
20
- };
21
- export const setSelectionRelativeToNode = (selectionRelativeToNode, selection) => createCommand({
22
- type: SelectionActionTypes.SET_RELATIVE_SELECTION,
23
- selectionRelativeToNode
24
- }, tr => {
25
- return selectNearNode(selectionRelativeToNode, selection)({
26
- tr
27
- }) || tr;
28
- });
29
- export const arrowRight = (state, dispatch) => {
30
- const {
31
- selection
32
- } = state;
33
- if (selection instanceof GapCursorSelection) {
34
- return arrowRightFromGapCursor(selection)(state, dispatch);
35
- } else if (selection instanceof NodeSelection) {
36
- return arrowRightFromNode(selection)(state, dispatch);
37
- } else if (selection instanceof TextSelection) {
38
- return arrowRightFromText(selection)(state, dispatch);
39
- }
40
- return false;
41
- };
42
- export const arrowLeft = (state, dispatch) => {
43
- const {
44
- selection
45
- } = state;
46
- if (selection instanceof GapCursorSelection) {
47
- return arrowLeftFromGapCursor(selection)(state, dispatch);
48
- } else if (selection instanceof NodeSelection) {
49
- return arrowLeftFromNode(selection)(state, dispatch);
50
- } else if (selection instanceof TextSelection) {
51
- return arrowLeftFromText(selection)(state, dispatch);
52
- }
53
- return false;
54
- };
55
- const arrowRightFromGapCursor = selection => (state, dispatch) => {
56
- const {
57
- $from,
58
- $to,
59
- side
60
- } = selection;
61
- if (side === Side.LEFT) {
62
- const selectableNode = findSelectableContainerAfter($to, state.doc);
63
- if (selectableNode) {
64
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
65
- }
66
- } else if (side === Side.RIGHT && isSelectionAtEndOfParentNode($from, selection)) {
67
- const selectableNode = findSelectableContainerParent(selection);
68
- if (selectableNode) {
69
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
70
- }
71
- }
72
- return false;
73
- };
74
- const arrowLeftFromGapCursor = selection => (state, dispatch) => {
75
- const {
76
- $from,
77
- side
78
- } = selection;
79
- const {
80
- selectionRelativeToNode
81
- } = getPluginState(state);
82
- if (side === Side.RIGHT) {
83
- const selectableNode = findSelectableContainerBefore($from, state.doc);
84
- if (selectableNode) {
85
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
86
- }
87
- } else if (side === Side.LEFT && isSelectionAtStartOfParentNode($from, selection)) {
88
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
89
- const $parent = state.doc.resolve(selection.$from.before(selection.$from.depth));
90
- if ($parent) {
91
- const selectableNode = findSelectableContainerBefore($parent, state.doc);
92
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
93
- // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
94
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
95
- }
96
- }
97
- // we don't return this as we want to reset the relative pos, but not block other plugins
98
- // from responding to arrow left key
99
- setSelectionRelativeToNode()(state, dispatch);
100
- } else {
101
- const selectableNode = findSelectableContainerParent(selection);
102
- if (selectableNode) {
103
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
104
- }
105
- }
106
- }
107
- return false;
108
- };
109
- const arrowRightFromNode = selection => (state, dispatch) => {
110
- const {
111
- node,
112
- from,
113
- $to
114
- } = selection;
115
- const {
116
- selectionRelativeToNode
117
- } = getPluginState(state);
118
- if (node.isAtom) {
119
- if (isSelectionAtEndOfParentNode($to, selection)) {
120
- // selection is for inline node that is the last child of its parent node - set text selection after it
121
- return findAndSetTextSelection(RelativeSelectionPos.End, state.doc.resolve(from + 1), SelectionDirection.After)(state, dispatch);
122
- }
123
- return false;
124
- } else if (selectionRelativeToNode === RelativeSelectionPos.Start) {
125
- // selection is for container node - set selection inside it at the start
126
- return setSelectionInsideAtNodeStart(RelativeSelectionPos.Inside, node, from)(state, dispatch);
127
- } else if (isIgnoredByGapCursor(node) && (!selectionRelativeToNode || selectionRelativeToNode === RelativeSelectionPos.End)) {
128
- const selectableNode = findSelectableContainerAfter($to, state.doc);
129
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
130
- // selection is for node without gap cursor followed by another node without gap cursor - set node selection for next node
131
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
132
- }
133
- }
134
- return false;
135
- };
136
- const arrowLeftFromNode = selection => (state, dispatch) => {
137
- const {
138
- node,
139
- from,
140
- to,
141
- $from
142
- } = selection;
143
- const {
144
- selectionRelativeToNode
145
- } = getPluginState(state);
146
- if (node.isAtom) {
147
- if (isSelectionAtStartOfParentNode($from, selection)) {
148
- // selection is for inline node that is the first child of its parent node - set text selection before it
149
- return findAndSetTextSelection(RelativeSelectionPos.Start, state.doc.resolve(from), SelectionDirection.Before)(state, dispatch);
150
- }
151
- return false;
152
- } else if (selectionRelativeToNode === RelativeSelectionPos.End) {
153
- // selection is for container node - set selection inside it at the end
154
- return setSelectionInsideAtNodeEnd(RelativeSelectionPos.Inside, node, from, to)(state, dispatch);
155
- } else if (!selectionRelativeToNode || selectionRelativeToNode === RelativeSelectionPos.Inside) {
156
- // selection is for container node - set selection inside it at the start
157
- // (this is a special case when the user selects by clicking node)
158
- return setSelectionInsideAtNodeStart(RelativeSelectionPos.Before, node, from)(state, dispatch);
159
- } else if (isIgnoredByGapCursor(node) && selectionRelativeToNode === RelativeSelectionPos.Start) {
160
- // selection is for node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
161
- const selectableNode = findSelectableContainerBefore($from, state.doc);
162
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
163
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
164
- }
165
- }
166
- return false;
167
- };
168
- const arrowRightFromText = selection => (state, dispatch) => {
169
- if (isSelectionAtEndOfParentNode(selection.$to, selection)) {
170
- const selectableNode = findSelectableContainerParent(selection);
171
- if (selectableNode) {
172
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
173
- }
174
- }
175
- return false;
176
- };
177
- const arrowLeftFromText = selection => (state, dispatch) => {
178
- const {
179
- selectionRelativeToNode
180
- } = getPluginState(state);
181
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
182
- const selectableNode = findSelectableContainerBefore(selection.$from, state.doc);
183
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
184
- // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
185
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
186
- }
187
- // we don't return this as we want to reset the relative pos, but not block other plugins
188
- // from responding to arrow left key
189
- setSelectionRelativeToNode(undefined)(state, dispatch);
190
- } else if (isSelectionAtStartOfParentNode(selection.$from, selection)) {
191
- const selectableNode = findSelectableContainerParent(selection);
192
- if (selectableNode) {
193
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
194
- }
195
- }
196
- return false;
197
- };
198
- const findAndSetTextSelection = (selectionRelativeToNode, $pos, dir) => (state, dispatch) => {
199
- const sel = Selection.findFrom($pos, dir, true);
200
- if (sel) {
201
- return setSelectionRelativeToNode(selectionRelativeToNode, sel)(state, dispatch);
202
- }
203
- return false;
204
- };
205
- const setSelectionInsideAtNodeStart = (selectionRelativeToNode, node, pos) => (state, dispatch) => {
206
- if (isNodeEmpty(node)) {
207
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(pos), SelectionDirection.After)(state, dispatch);
208
- }
209
- const selectableNode = findFirstChildNodeToSelect(node);
210
- if (selectableNode) {
211
- const {
212
- node: childNode,
213
- pos: childPos
214
- } = selectableNode;
215
- const selectionPos = pos + childPos + 1;
216
- if (childNode.isText || childNode.isAtom) {
217
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos), SelectionDirection.Before)(state, dispatch);
218
- } else if (isEmptyParagraph(childNode)) {
219
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos + 1), SelectionDirection.Before)(state, dispatch);
220
- } else if (!isIgnoredByGapCursor(node)) {
221
- return setSelectionRelativeToNode(selectionRelativeToNode, new GapCursorSelection(state.doc.resolve(selectionPos), Side.LEFT))(state, dispatch);
222
- } else if (isSelectableContainerNode(node)) {
223
- return setSelectionRelativeToNode(selectionRelativeToNode, NodeSelection.create(state.doc, selectionPos))(state, dispatch);
224
- }
225
- }
226
- return false;
227
- };
228
- export const setSelectionInsideAtNodeEnd = (selectionRelativeToNode, node, from, to) => (state, dispatch) => {
229
- if (isNodeEmpty(node)) {
230
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(to), SelectionDirection.Before)(state, dispatch);
231
- }
232
- const selectableNode = findLastChildNodeToSelect(node);
233
- if (selectableNode) {
234
- const {
235
- node: childNode,
236
- pos: childPos
237
- } = selectableNode;
238
- const selectionPos = from + childPos + childNode.nodeSize;
239
- if (childNode.isText || childNode.isAtom) {
240
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos + 1), SelectionDirection.After)(state, dispatch);
241
- } else if (isEmptyParagraph(childNode)) {
242
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos), SelectionDirection.After)(state, dispatch);
243
- } else if (!isIgnoredByGapCursor(node)) {
244
- return setSelectionRelativeToNode(selectionRelativeToNode, new GapCursorSelection(state.doc.resolve(selectionPos + 1), Side.RIGHT))(state, dispatch);
245
- } else if (isSelectableContainerNode(node)) {
246
- return setSelectionRelativeToNode(selectionRelativeToNode, NodeSelection.create(state.doc, selectionPos))(state, dispatch);
247
- }
248
- }
249
- return false;
250
- };