@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,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
- };
@@ -1,270 +0,0 @@
1
- import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { findDomRefAtPos, findPositionOfNodeBefore, removeNodeBefore } from '@atlaskit/editor-prosemirror/utils';
3
- import { Direction, isBackward, isForward } from './direction';
4
- import { GapCursorSelection, Side } from './selection';
5
- import { isTextBlockNearPos } from './utils';
6
- import { isValidTargetNode } from './utils/is-valid-target-node';
7
- import { atTheBeginningOfDoc, atTheEndOfDoc } from '@atlaskit/editor-common/selection';
8
- import { gapCursorPluginKey } from '../pm-plugins/gap-cursor-plugin-key';
9
- import { ZERO_WIDTH_SPACE, isMediaNode, isNodeBeforeMediaNode, isPositionNearTableRow } from '@atlaskit/editor-common/utils';
10
- export const shouldSkipGapCursor = (direction, state, $pos) => {
11
- var _$pos$nodeBefore;
12
- const {
13
- doc,
14
- schema
15
- } = state;
16
- switch (direction) {
17
- case Direction.UP:
18
- if (atTheBeginningOfDoc(state)) {
19
- return false;
20
- }
21
- return isPositionNearTableRow($pos, schema, 'before') || isTextBlockNearPos(doc, schema, $pos, -1) || isNodeBeforeMediaNode($pos, state);
22
- case Direction.DOWN:
23
- return atTheEndOfDoc(state) || isTextBlockNearPos(doc, schema, $pos, 1) || isPositionNearTableRow($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter // end of a paragraph
24
- ;
25
-
26
- default:
27
- return false;
28
- }
29
- };
30
-
31
- // These cases should be handled using the handleMediaGapCursor function
32
- function shouldHandleMediaGapCursor(dir, state) {
33
- var _selection$$from$node;
34
- const {
35
- selection
36
- } = state;
37
- const upArrowFromGapCursorIntoMedia = selection instanceof GapCursorSelection && dir === Direction.UP && selection.$from.nodeBefore && isMediaNode(selection.$from.nodeBefore);
38
- const downArrowFromGapCursorIntoMediaGroup = selection instanceof GapCursorSelection && dir === Direction.DOWN && ((_selection$$from$node = selection.$from.nodeAfter) === null || _selection$$from$node === void 0 ? void 0 : _selection$$from$node.type.name) === 'mediaGroup';
39
- return upArrowFromGapCursorIntoMedia || downArrowFromGapCursorIntoMediaGroup;
40
- }
41
-
42
- // Handle media gap cursor for up/down arrow into media nodes
43
- // Should check this case by using shouldHandleMediaGapCursor first
44
- function handleMediaGapCursor(dir, state) {
45
- const {
46
- selection,
47
- tr
48
- } = state;
49
- let $pos = isBackward(dir) ? selection.$from : selection.$to;
50
- if (dir === Direction.UP && selection.$from.nodeBefore && isMediaNode(selection.$from.nodeBefore)) {
51
- var _tr$doc$nodeAt;
52
- const nodeBeforePos = findPositionOfNodeBefore(tr.selection);
53
- if (nodeBeforePos && selection.side === 'right' && ((_tr$doc$nodeAt = tr.doc.nodeAt(nodeBeforePos)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.type.name) === 'mediaSingle') {
54
- tr.setSelection(new NodeSelection(tr.doc.resolve(nodeBeforePos))).scrollIntoView();
55
- } else if (nodeBeforePos || nodeBeforePos === 0) {
56
- tr.setSelection(new GapCursorSelection(tr.doc.resolve(nodeBeforePos), Side.LEFT)).scrollIntoView();
57
- }
58
- }
59
- if (dir === Direction.DOWN && selection.$from.nodeAfter) {
60
- const nodeAfterPos = selection.side === 'right' ? $pos.pos : $pos.pos + selection.$from.nodeAfter.nodeSize;
61
- if (nodeAfterPos) {
62
- tr.setSelection(new GapCursorSelection(tr.doc.resolve(nodeAfterPos), Side.LEFT)).scrollIntoView();
63
- }
64
- }
65
- return tr;
66
- }
67
- export const arrow = (dir, endOfTextblock) => (state, dispatch, view) => {
68
- const {
69
- doc,
70
- selection,
71
- tr
72
- } = state;
73
- let $pos = isBackward(dir) ? selection.$from : selection.$to;
74
- let mustMove = selection.empty;
75
-
76
- // start from text selection
77
- if (selection instanceof TextSelection) {
78
- // if cursor is in the middle of a text node, do nothing
79
- if (!endOfTextblock || !endOfTextblock(dir.toString())) {
80
- return false;
81
- }
82
-
83
- // UP/DOWN jumps to the nearest texblock skipping gapcursor whenever possible
84
- if (shouldSkipGapCursor(dir, state, $pos)) {
85
- return false;
86
- }
87
-
88
- // otherwise resolve previous/next position
89
- $pos = doc.resolve(isBackward(dir) ? $pos.before() : $pos.after());
90
- mustMove = false;
91
- }
92
- if (selection instanceof NodeSelection) {
93
- if (selection.node.isInline) {
94
- return false;
95
- }
96
- if (dir === Direction.UP && !atTheBeginningOfDoc(state) && !isNodeBeforeMediaNode($pos, state) || dir === Direction.DOWN) {
97
- // We dont add gap cursor on node selections going up and down
98
- // Except we do if we're going up for a block node which is the
99
- // first node in the document OR the node before is a media node
100
- return false;
101
- }
102
- }
103
-
104
- // Handle media gap cursor for up/down arrow into media nodes
105
- if (shouldHandleMediaGapCursor(dir, state)) {
106
- const updatedTr = handleMediaGapCursor(dir, state);
107
- if (dispatch) {
108
- dispatch(updatedTr);
109
- }
110
- return true;
111
- }
112
-
113
- // when jumping between block nodes at the same depth, we need to reverse cursor without changing ProseMirror position
114
- if (selection instanceof GapCursorSelection &&
115
- // next node allow gap cursor position
116
- isValidTargetNode(isBackward(dir) ? $pos.nodeBefore : $pos.nodeAfter) && (
117
- // gap cursor changes block node
118
- isBackward(dir) && selection.side === Side.LEFT || isForward(dir) && selection.side === Side.RIGHT)) {
119
- // reverse cursor position
120
- if (dispatch) {
121
- dispatch(tr.setSelection(new GapCursorSelection($pos, selection.side === Side.RIGHT ? Side.LEFT : Side.RIGHT)).scrollIntoView());
122
- }
123
- return true;
124
- }
125
- if (view) {
126
- const domAtPos = view.domAtPos.bind(view);
127
- const target = findDomRefAtPos($pos.pos, domAtPos);
128
- if (target && target.textContent === ZERO_WIDTH_SPACE) {
129
- return false;
130
- }
131
- }
132
- const nextSelection = GapCursorSelection.findFrom($pos, isBackward(dir) ? -1 : 1, mustMove);
133
- if (!nextSelection) {
134
- return false;
135
- }
136
- if (!isValidTargetNode(isForward(dir) ? nextSelection.$from.nodeBefore : nextSelection.$from.nodeAfter)) {
137
- // reverse cursor position
138
- if (dispatch) {
139
- dispatch(tr.setSelection(new GapCursorSelection(nextSelection.$from, isForward(dir) ? Side.LEFT : Side.RIGHT)).scrollIntoView());
140
- }
141
- return true;
142
- }
143
- if (dispatch) {
144
- dispatch(tr.setSelection(nextSelection).scrollIntoView());
145
- }
146
- return true;
147
- };
148
- export const deleteNode = dir => (state, dispatch) => {
149
- if (state.selection instanceof GapCursorSelection) {
150
- const {
151
- $from,
152
- $anchor
153
- } = state.selection;
154
- let {
155
- tr
156
- } = state;
157
- if (isBackward(dir)) {
158
- if (state.selection.side === 'left') {
159
- tr.setSelection(new GapCursorSelection($anchor, Side.RIGHT));
160
- if (dispatch) {
161
- dispatch(tr);
162
- }
163
- return true;
164
- }
165
- tr = removeNodeBefore(state.tr);
166
- } else if ($from.nodeAfter) {
167
- tr = tr.delete($from.pos, $from.pos + $from.nodeAfter.nodeSize);
168
- }
169
- if (dispatch) {
170
- dispatch(tr.setSelection(Selection.near(tr.doc.resolve(tr.mapping.map(state.selection.$from.pos)))).scrollIntoView());
171
- }
172
- return true;
173
- }
174
- return false;
175
- };
176
- export const setGapCursorAtPos = (position, side = Side.LEFT) => (state, dispatch) => {
177
- // @see ED-6231
178
- if (position > state.doc.content.size) {
179
- return false;
180
- }
181
- const $pos = state.doc.resolve(position);
182
- if (GapCursorSelection.valid($pos)) {
183
- if (dispatch) {
184
- dispatch(state.tr.setSelection(new GapCursorSelection($pos, side)));
185
- }
186
- return true;
187
- }
188
- return false;
189
- };
190
-
191
- // This function captures clicks outside of the ProseMirror contentEditable area
192
- // see also description of "handleClick" in gap-cursor pm-plugin
193
- const captureCursorCoords = (event, editorRef, posAtCoords, tr) => {
194
- const rect = editorRef.getBoundingClientRect();
195
-
196
- // capture clicks before the first block element
197
- if (event.clientY < rect.top) {
198
- return {
199
- position: 0,
200
- side: Side.LEFT
201
- };
202
- }
203
- if (rect.left > 0) {
204
- // calculate start position of a node that is vertically at the same level
205
- const coords = posAtCoords({
206
- left: rect.left,
207
- top: event.clientY
208
- });
209
- if (coords && coords.inside > -1) {
210
- const $from = tr.doc.resolve(coords.inside);
211
- const start = $from.before(1);
212
- const side = event.clientX < rect.left ? Side.LEFT : Side.RIGHT;
213
- let position;
214
- if (side === Side.LEFT) {
215
- position = start;
216
- } else {
217
- const node = tr.doc.nodeAt(start);
218
- if (node) {
219
- position = start + node.nodeSize;
220
- }
221
- }
222
- return {
223
- position,
224
- side
225
- };
226
- }
227
- }
228
- return null;
229
- };
230
- export const setSelectionTopLevelBlocks = (tr, event, editorRef, posAtCoords, editorFocused) => {
231
- const cursorCoords = captureCursorCoords(event, editorRef, posAtCoords, tr);
232
- if (!cursorCoords) {
233
- return;
234
- }
235
- const $pos = cursorCoords.position !== undefined ? tr.doc.resolve(cursorCoords.position) : null;
236
- if ($pos === null) {
237
- return;
238
- }
239
- const isGapCursorAllowed = cursorCoords.side === Side.LEFT ? isValidTargetNode($pos.nodeAfter) : isValidTargetNode($pos.nodeBefore);
240
- if (isGapCursorAllowed && GapCursorSelection.valid($pos)) {
241
- // this forces PM to re-render the decoration node if we change the side of the gap cursor, it doesn't do it by default
242
- if (tr.selection instanceof GapCursorSelection) {
243
- tr.setSelection(Selection.near($pos));
244
- } else {
245
- tr.setSelection(new GapCursorSelection($pos, cursorCoords.side));
246
- }
247
- }
248
- // try to set text selection if the editor isnt focused
249
- // if the editor is focused, we are most likely dragging a selection outside.
250
- else if (editorFocused === false) {
251
- const selectionTemp = Selection.findFrom($pos, cursorCoords.side === Side.LEFT ? 1 : -1, true);
252
- if (selectionTemp) {
253
- tr.setSelection(selectionTemp);
254
- }
255
- }
256
- };
257
- export const setCursorForTopLevelBlocks = (event, editorRef, posAtCoords, editorFocused) => (state, dispatch) => {
258
- const {
259
- tr
260
- } = state;
261
- setSelectionTopLevelBlocks(tr, event, editorRef, posAtCoords, editorFocused);
262
- if (tr.selectionSet && dispatch) {
263
- dispatch(tr);
264
- return true;
265
- }
266
- return false;
267
- };
268
- export const hasGapCursorPlugin = state => {
269
- return Boolean(gapCursorPluginKey.get(state));
270
- };
@@ -1,15 +0,0 @@
1
- export let Direction = /*#__PURE__*/function (Direction) {
2
- Direction["UP"] = "up";
3
- Direction["RIGHT"] = "right";
4
- Direction["DOWN"] = "down";
5
- Direction["LEFT"] = "left";
6
- Direction["BACKWARD"] = "backward";
7
- Direction["FORWARD"] = "forward";
8
- return Direction;
9
- }({});
10
- export function isBackward(dir) {
11
- return [Direction.UP, Direction.LEFT, Direction.BACKWARD].indexOf(dir) !== -1;
12
- }
13
- export function isForward(dir) {
14
- return [Direction.RIGHT, Direction.DOWN, Direction.FORWARD].indexOf(dir) !== -1;
15
- }
@@ -1 +0,0 @@
1
- export { GapCursorSelection, JSON_ID, Side, GapBookmark } from '@atlaskit/editor-common/selection';
@@ -1,145 +0,0 @@
1
- import { css, keyframes } from '@emotion/react';
2
- const gapCursorBlink = keyframes`
3
- from, to {
4
- opacity: 0;
5
- }
6
- 50% {
7
- opacity: 1;
8
- }
9
- `;
10
- export const hideCaretModifier = 'ProseMirror-hide-gapcursor';
11
- const gapCursor = '.ProseMirror-gapcursor';
12
- const prosemirrorwidget = '.ProseMirror-widget';
13
- const wrapLeft = '[layout="wrap-left"]';
14
- const wrapRight = '[layout="wrap-right"]';
15
- export const gapCursorStyles = css`
16
- /* =============== GAP CURSOR ================== */
17
- .ProseMirror {
18
- &.${hideCaretModifier} {
19
- caret-color: transparent;
20
- }
21
-
22
- ${gapCursor} {
23
- display: none;
24
- pointer-events: none;
25
- position: relative;
26
-
27
- & span {
28
- caret-color: transparent;
29
- position: absolute;
30
- height: 100%;
31
- width: 100%;
32
- display: block;
33
- }
34
-
35
- & span::after {
36
- animation: 1s ${gapCursorBlink} step-end infinite;
37
- border-left: 1px solid;
38
- content: '';
39
- display: block;
40
- position: absolute;
41
- top: 0;
42
- height: 100%;
43
- }
44
- &.-left span::after {
45
- left: -3px;
46
- }
47
- &.-right span::after {
48
- right: -3px;
49
- }
50
- & span[layout='full-width'],
51
- & span[layout='wide'],
52
- & span[layout='fixed-width'] {
53
- margin-left: 50%;
54
- transform: translateX(-50%);
55
- }
56
- &${wrapRight} {
57
- float: right;
58
- }
59
-
60
- /* fix vertical alignment of gap cursor */
61
- &:first-of-type + ul,
62
- &:first-of-type + span + ul,
63
- &:first-of-type + ol,
64
- &:first-of-type + span + ol,
65
- &:first-of-type + pre,
66
- &:first-of-type + span + pre,
67
- &:first-of-type + blockquote,
68
- &:first-of-type + span + blockquote {
69
- margin-top: 0;
70
- }
71
- }
72
- &.ProseMirror-focused ${gapCursor} {
73
- display: block;
74
- border-color: transparent;
75
- }
76
- }
77
-
78
- /* This hack below is for two images aligned side by side */
79
- ${gapCursor}${wrapLeft} + span + ${wrapLeft},
80
- ${gapCursor}${wrapRight} + span + ${wrapRight},
81
- ${gapCursor} + ${wrapLeft} + ${wrapRight},
82
- ${gapCursor} + ${wrapLeft} + span + ${wrapRight},
83
- ${gapCursor} + ${wrapRight} + ${wrapLeft},
84
- ${gapCursor} + ${wrapRight} + span + ${wrapLeft},
85
- ${wrapLeft} + ${gapCursor} + ${wrapRight},
86
- ${wrapLeft} + ${gapCursor} + span ${wrapRight},
87
- ${wrapRight} + ${gapCursor} + ${wrapLeft},
88
- ${wrapRight} + ${gapCursor} + span + ${wrapLeft},
89
- ${wrapLeft} + ${gapCursor} {
90
- clear: none;
91
- }
92
-
93
- ${wrapLeft} + ${gapCursor} + ${wrapRight} > div,
94
- ${wrapLeft} + ${gapCursor} + span + ${wrapRight} > div,
95
- ${wrapRight} + ${gapCursor} + ${wrapLeft} > div,
96
- ${wrapRight} + ${gapCursor} + span + ${wrapLeft} > div,
97
- ${gapCursor} + ${wrapRight} + ${wrapLeft} > div,
98
- ${gapCursor} + ${wrapRight} + span + ${wrapLeft} > div,
99
- ${gapCursor} + ${wrapLeft} + ${wrapRight} > div,
100
- ${gapCursor} + ${wrapLeft} + span + ${wrapRight} > div {
101
- margin-right: 0;
102
- margin-left: 0;
103
- margin-bottom: 0;
104
- }
105
-
106
- ${wrapLeft} + ${gapCursor},
107
- ${wrapRight} + ${gapCursor} {
108
- float: left;
109
- }
110
-
111
- ${gapCursor} + ${wrapLeft} + span + ${wrapRight}::after,
112
- ${gapCursor} + ${wrapRight} + span + ${wrapLeft}::after,
113
- ${wrapLeft} + ${gapCursor} + ${wrapRight}::after,
114
- ${wrapLeft} + ${gapCursor} + span + ${wrapRight}::after,
115
- ${wrapRight} + ${gapCursor} + ${wrapLeft}::after,
116
- ${wrapRight} + ${gapCursor} + span + ${wrapLeft}::after {
117
- visibility: hidden;
118
- display: block;
119
- font-size: 0;
120
- content: ' ';
121
- clear: both;
122
- height: 0;
123
- }
124
-
125
- ${wrapLeft} + ${gapCursor} + ${wrapRight} + *,
126
- ${wrapLeft} + ${gapCursor} + ${wrapRight} + span + *,
127
- ${wrapRight} + ${gapCursor} + ${wrapLeft} + *,
128
- ${wrapRight} + ${gapCursor} + ${wrapLeft} + span + *,
129
- ${wrapLeft} + ${gapCursor} + span + ${wrapRight} + *,
130
- ${wrapRight} + ${gapCursor} + span + ${wrapLeft} + *,
131
- ${gapCursor} + ${wrapLeft} + span + ${wrapRight} + *,
132
- ${gapCursor} + ${wrapRight} + span + ${wrapLeft} + *,
133
- ${wrapLeft} + ${gapCursor} + ${wrapRight} + * > *,
134
- ${wrapLeft} + ${gapCursor} + ${wrapRight} + span + * > *,
135
- ${wrapRight} + ${gapCursor} + ${wrapLeft} + * > *,
136
- ${wrapRight} + ${gapCursor} + ${wrapLeft} + span + * > *,
137
- ${wrapLeft} + ${gapCursor} + span + ${wrapRight} + * > *,
138
- ${wrapRight} + ${gapCursor} + span + ${wrapLeft} + * > *,
139
- ${gapCursor} + ${wrapLeft} + span + ${wrapRight} + * > *,
140
- ${gapCursor} + ${wrapRight} + span + ${wrapLeft} + * > *,
141
- ${prosemirrorwidget} + ${gapCursor} + *,
142
- ${prosemirrorwidget} + ${gapCursor} + span + * {
143
- margin-top: 0;
144
- }
145
- `;
@@ -1 +0,0 @@
1
- export { isIgnored } from '@atlaskit/editor-common/selection';
@@ -1 +0,0 @@
1
- export { isValidTargetNode } from '@atlaskit/editor-common/selection';