@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,251 +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 var selectNearNode = function selectNearNode(selectionRelativeToNode, selection) {
10
- return function (_ref) {
11
- var tr = _ref.tr;
12
- tr.setMeta(selectionPluginKey, {
13
- type: SelectionActionTypes.SET_RELATIVE_SELECTION,
14
- selectionRelativeToNode: selectionRelativeToNode
15
- });
16
- if (selection) {
17
- return tr.setSelection(selection);
18
- }
19
- return tr;
20
- };
21
- };
22
- export var setSelectionRelativeToNode = function setSelectionRelativeToNode(selectionRelativeToNode, selection) {
23
- return createCommand({
24
- type: SelectionActionTypes.SET_RELATIVE_SELECTION,
25
- selectionRelativeToNode: selectionRelativeToNode
26
- }, function (tr) {
27
- return selectNearNode(selectionRelativeToNode, selection)({
28
- tr: tr
29
- }) || tr;
30
- });
31
- };
32
- export var arrowRight = function arrowRight(state, dispatch) {
33
- var selection = state.selection;
34
- if (selection instanceof GapCursorSelection) {
35
- return arrowRightFromGapCursor(selection)(state, dispatch);
36
- } else if (selection instanceof NodeSelection) {
37
- return arrowRightFromNode(selection)(state, dispatch);
38
- } else if (selection instanceof TextSelection) {
39
- return arrowRightFromText(selection)(state, dispatch);
40
- }
41
- return false;
42
- };
43
- export var arrowLeft = function arrowLeft(state, dispatch) {
44
- var selection = state.selection;
45
- if (selection instanceof GapCursorSelection) {
46
- return arrowLeftFromGapCursor(selection)(state, dispatch);
47
- } else if (selection instanceof NodeSelection) {
48
- return arrowLeftFromNode(selection)(state, dispatch);
49
- } else if (selection instanceof TextSelection) {
50
- return arrowLeftFromText(selection)(state, dispatch);
51
- }
52
- return false;
53
- };
54
- var arrowRightFromGapCursor = function arrowRightFromGapCursor(selection) {
55
- return function (state, dispatch) {
56
- var $from = selection.$from,
57
- $to = selection.$to,
58
- side = selection.side;
59
- if (side === Side.LEFT) {
60
- var selectableNode = findSelectableContainerAfter($to, state.doc);
61
- if (selectableNode) {
62
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
63
- }
64
- } else if (side === Side.RIGHT && isSelectionAtEndOfParentNode($from, selection)) {
65
- var _selectableNode = findSelectableContainerParent(selection);
66
- if (_selectableNode) {
67
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, _selectableNode.pos))(state, dispatch);
68
- }
69
- }
70
- return false;
71
- };
72
- };
73
- var arrowLeftFromGapCursor = function arrowLeftFromGapCursor(selection) {
74
- return function (state, dispatch) {
75
- var $from = selection.$from,
76
- side = selection.side;
77
- var _getPluginState = getPluginState(state),
78
- selectionRelativeToNode = _getPluginState.selectionRelativeToNode;
79
- if (side === Side.RIGHT) {
80
- var selectableNode = findSelectableContainerBefore($from, state.doc);
81
- if (selectableNode) {
82
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
83
- }
84
- } else if (side === Side.LEFT && isSelectionAtStartOfParentNode($from, selection)) {
85
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
86
- var $parent = state.doc.resolve(selection.$from.before(selection.$from.depth));
87
- if ($parent) {
88
- var _selectableNode2 = findSelectableContainerBefore($parent, state.doc);
89
- if (_selectableNode2 && isIgnoredByGapCursor(_selectableNode2.node)) {
90
- // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
91
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, _selectableNode2.pos))(state, dispatch);
92
- }
93
- }
94
- // we don't return this as we want to reset the relative pos, but not block other plugins
95
- // from responding to arrow left key
96
- setSelectionRelativeToNode()(state, dispatch);
97
- } else {
98
- var _selectableNode3 = findSelectableContainerParent(selection);
99
- if (_selectableNode3) {
100
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, _selectableNode3.pos))(state, dispatch);
101
- }
102
- }
103
- }
104
- return false;
105
- };
106
- };
107
- var arrowRightFromNode = function arrowRightFromNode(selection) {
108
- return function (state, dispatch) {
109
- var node = selection.node,
110
- from = selection.from,
111
- $to = selection.$to;
112
- var _getPluginState2 = getPluginState(state),
113
- selectionRelativeToNode = _getPluginState2.selectionRelativeToNode;
114
- if (node.isAtom) {
115
- if (isSelectionAtEndOfParentNode($to, selection)) {
116
- // selection is for inline node that is the last child of its parent node - set text selection after it
117
- return findAndSetTextSelection(RelativeSelectionPos.End, state.doc.resolve(from + 1), SelectionDirection.After)(state, dispatch);
118
- }
119
- return false;
120
- } else if (selectionRelativeToNode === RelativeSelectionPos.Start) {
121
- // selection is for container node - set selection inside it at the start
122
- return setSelectionInsideAtNodeStart(RelativeSelectionPos.Inside, node, from)(state, dispatch);
123
- } else if (isIgnoredByGapCursor(node) && (!selectionRelativeToNode || selectionRelativeToNode === RelativeSelectionPos.End)) {
124
- var selectableNode = findSelectableContainerAfter($to, state.doc);
125
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
126
- // selection is for node without gap cursor followed by another node without gap cursor - set node selection for next node
127
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
128
- }
129
- }
130
- return false;
131
- };
132
- };
133
- var arrowLeftFromNode = function arrowLeftFromNode(selection) {
134
- return function (state, dispatch) {
135
- var node = selection.node,
136
- from = selection.from,
137
- to = selection.to,
138
- $from = selection.$from;
139
- var _getPluginState3 = getPluginState(state),
140
- selectionRelativeToNode = _getPluginState3.selectionRelativeToNode;
141
- if (node.isAtom) {
142
- if (isSelectionAtStartOfParentNode($from, selection)) {
143
- // selection is for inline node that is the first child of its parent node - set text selection before it
144
- return findAndSetTextSelection(RelativeSelectionPos.Start, state.doc.resolve(from), SelectionDirection.Before)(state, dispatch);
145
- }
146
- return false;
147
- } else if (selectionRelativeToNode === RelativeSelectionPos.End) {
148
- // selection is for container node - set selection inside it at the end
149
- return setSelectionInsideAtNodeEnd(RelativeSelectionPos.Inside, node, from, to)(state, dispatch);
150
- } else if (!selectionRelativeToNode || selectionRelativeToNode === RelativeSelectionPos.Inside) {
151
- // selection is for container node - set selection inside it at the start
152
- // (this is a special case when the user selects by clicking node)
153
- return setSelectionInsideAtNodeStart(RelativeSelectionPos.Before, node, from)(state, dispatch);
154
- } else if (isIgnoredByGapCursor(node) && selectionRelativeToNode === RelativeSelectionPos.Start) {
155
- // selection is for node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
156
- var selectableNode = findSelectableContainerBefore($from, state.doc);
157
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
158
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
159
- }
160
- }
161
- return false;
162
- };
163
- };
164
- var arrowRightFromText = function arrowRightFromText(selection) {
165
- return function (state, dispatch) {
166
- if (isSelectionAtEndOfParentNode(selection.$to, selection)) {
167
- var selectableNode = findSelectableContainerParent(selection);
168
- if (selectableNode) {
169
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
170
- }
171
- }
172
- return false;
173
- };
174
- };
175
- var arrowLeftFromText = function arrowLeftFromText(selection) {
176
- return function (state, dispatch) {
177
- var _getPluginState4 = getPluginState(state),
178
- selectionRelativeToNode = _getPluginState4.selectionRelativeToNode;
179
- if (selectionRelativeToNode === RelativeSelectionPos.Before) {
180
- var selectableNode = findSelectableContainerBefore(selection.$from, state.doc);
181
- if (selectableNode && isIgnoredByGapCursor(selectableNode.node)) {
182
- // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
183
- return setSelectionRelativeToNode(RelativeSelectionPos.End, NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
184
- }
185
- // we don't return this as we want to reset the relative pos, but not block other plugins
186
- // from responding to arrow left key
187
- setSelectionRelativeToNode(undefined)(state, dispatch);
188
- } else if (isSelectionAtStartOfParentNode(selection.$from, selection)) {
189
- var _selectableNode4 = findSelectableContainerParent(selection);
190
- if (_selectableNode4) {
191
- return setSelectionRelativeToNode(RelativeSelectionPos.Start, NodeSelection.create(state.doc, _selectableNode4.pos))(state, dispatch);
192
- }
193
- }
194
- return false;
195
- };
196
- };
197
- var findAndSetTextSelection = function findAndSetTextSelection(selectionRelativeToNode, $pos, dir) {
198
- return function (state, dispatch) {
199
- var sel = Selection.findFrom($pos, dir, true);
200
- if (sel) {
201
- return setSelectionRelativeToNode(selectionRelativeToNode, sel)(state, dispatch);
202
- }
203
- return false;
204
- };
205
- };
206
- var setSelectionInsideAtNodeStart = function setSelectionInsideAtNodeStart(selectionRelativeToNode, node, pos) {
207
- return function (state, dispatch) {
208
- if (isNodeEmpty(node)) {
209
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(pos), SelectionDirection.After)(state, dispatch);
210
- }
211
- var selectableNode = findFirstChildNodeToSelect(node);
212
- if (selectableNode) {
213
- var childNode = selectableNode.node,
214
- childPos = selectableNode.pos;
215
- var 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
- };
229
- export var setSelectionInsideAtNodeEnd = function setSelectionInsideAtNodeEnd(selectionRelativeToNode, node, from, to) {
230
- return function (state, dispatch) {
231
- if (isNodeEmpty(node)) {
232
- return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(to), SelectionDirection.Before)(state, dispatch);
233
- }
234
- var selectableNode = findLastChildNodeToSelect(node);
235
- if (selectableNode) {
236
- var childNode = selectableNode.node,
237
- childPos = selectableNode.pos;
238
- var 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
- };
251
- };
@@ -1,266 +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 var shouldSkipGapCursor = function shouldSkipGapCursor(direction, state, $pos) {
11
- var _$pos$nodeBefore;
12
- var doc = state.doc,
13
- schema = state.schema;
14
- switch (direction) {
15
- case Direction.UP:
16
- if (atTheBeginningOfDoc(state)) {
17
- return false;
18
- }
19
- return isPositionNearTableRow($pos, schema, 'before') || isTextBlockNearPos(doc, schema, $pos, -1) || isNodeBeforeMediaNode($pos, state);
20
- case Direction.DOWN:
21
- 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
22
- ;
23
-
24
- default:
25
- return false;
26
- }
27
- };
28
-
29
- // These cases should be handled using the handleMediaGapCursor function
30
- function shouldHandleMediaGapCursor(dir, state) {
31
- var _selection$$from$node;
32
- var selection = state.selection;
33
- var upArrowFromGapCursorIntoMedia = selection instanceof GapCursorSelection && dir === Direction.UP && selection.$from.nodeBefore && isMediaNode(selection.$from.nodeBefore);
34
- var 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';
35
- return upArrowFromGapCursorIntoMedia || downArrowFromGapCursorIntoMediaGroup;
36
- }
37
-
38
- // Handle media gap cursor for up/down arrow into media nodes
39
- // Should check this case by using shouldHandleMediaGapCursor first
40
- function handleMediaGapCursor(dir, state) {
41
- var selection = state.selection,
42
- tr = state.tr;
43
- var $pos = isBackward(dir) ? selection.$from : selection.$to;
44
- if (dir === Direction.UP && selection.$from.nodeBefore && isMediaNode(selection.$from.nodeBefore)) {
45
- var _tr$doc$nodeAt;
46
- var nodeBeforePos = findPositionOfNodeBefore(tr.selection);
47
- 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') {
48
- tr.setSelection(new NodeSelection(tr.doc.resolve(nodeBeforePos))).scrollIntoView();
49
- } else if (nodeBeforePos || nodeBeforePos === 0) {
50
- tr.setSelection(new GapCursorSelection(tr.doc.resolve(nodeBeforePos), Side.LEFT)).scrollIntoView();
51
- }
52
- }
53
- if (dir === Direction.DOWN && selection.$from.nodeAfter) {
54
- var nodeAfterPos = selection.side === 'right' ? $pos.pos : $pos.pos + selection.$from.nodeAfter.nodeSize;
55
- if (nodeAfterPos) {
56
- tr.setSelection(new GapCursorSelection(tr.doc.resolve(nodeAfterPos), Side.LEFT)).scrollIntoView();
57
- }
58
- }
59
- return tr;
60
- }
61
- export var arrow = function arrow(dir, endOfTextblock) {
62
- return function (state, dispatch, view) {
63
- var doc = state.doc,
64
- selection = state.selection,
65
- tr = state.tr;
66
- var $pos = isBackward(dir) ? selection.$from : selection.$to;
67
- var mustMove = selection.empty;
68
-
69
- // start from text selection
70
- if (selection instanceof TextSelection) {
71
- // if cursor is in the middle of a text node, do nothing
72
- if (!endOfTextblock || !endOfTextblock(dir.toString())) {
73
- return false;
74
- }
75
-
76
- // UP/DOWN jumps to the nearest texblock skipping gapcursor whenever possible
77
- if (shouldSkipGapCursor(dir, state, $pos)) {
78
- return false;
79
- }
80
-
81
- // otherwise resolve previous/next position
82
- $pos = doc.resolve(isBackward(dir) ? $pos.before() : $pos.after());
83
- mustMove = false;
84
- }
85
- if (selection instanceof NodeSelection) {
86
- if (selection.node.isInline) {
87
- return false;
88
- }
89
- if (dir === Direction.UP && !atTheBeginningOfDoc(state) && !isNodeBeforeMediaNode($pos, state) || dir === Direction.DOWN) {
90
- // We dont add gap cursor on node selections going up and down
91
- // Except we do if we're going up for a block node which is the
92
- // first node in the document OR the node before is a media node
93
- return false;
94
- }
95
- }
96
-
97
- // Handle media gap cursor for up/down arrow into media nodes
98
- if (shouldHandleMediaGapCursor(dir, state)) {
99
- var updatedTr = handleMediaGapCursor(dir, state);
100
- if (dispatch) {
101
- dispatch(updatedTr);
102
- }
103
- return true;
104
- }
105
-
106
- // when jumping between block nodes at the same depth, we need to reverse cursor without changing ProseMirror position
107
- if (selection instanceof GapCursorSelection &&
108
- // next node allow gap cursor position
109
- isValidTargetNode(isBackward(dir) ? $pos.nodeBefore : $pos.nodeAfter) && (
110
- // gap cursor changes block node
111
- isBackward(dir) && selection.side === Side.LEFT || isForward(dir) && selection.side === Side.RIGHT)) {
112
- // reverse cursor position
113
- if (dispatch) {
114
- dispatch(tr.setSelection(new GapCursorSelection($pos, selection.side === Side.RIGHT ? Side.LEFT : Side.RIGHT)).scrollIntoView());
115
- }
116
- return true;
117
- }
118
- if (view) {
119
- var domAtPos = view.domAtPos.bind(view);
120
- var target = findDomRefAtPos($pos.pos, domAtPos);
121
- if (target && target.textContent === ZERO_WIDTH_SPACE) {
122
- return false;
123
- }
124
- }
125
- var nextSelection = GapCursorSelection.findFrom($pos, isBackward(dir) ? -1 : 1, mustMove);
126
- if (!nextSelection) {
127
- return false;
128
- }
129
- if (!isValidTargetNode(isForward(dir) ? nextSelection.$from.nodeBefore : nextSelection.$from.nodeAfter)) {
130
- // reverse cursor position
131
- if (dispatch) {
132
- dispatch(tr.setSelection(new GapCursorSelection(nextSelection.$from, isForward(dir) ? Side.LEFT : Side.RIGHT)).scrollIntoView());
133
- }
134
- return true;
135
- }
136
- if (dispatch) {
137
- dispatch(tr.setSelection(nextSelection).scrollIntoView());
138
- }
139
- return true;
140
- };
141
- };
142
- export var deleteNode = function deleteNode(dir) {
143
- return function (state, dispatch) {
144
- if (state.selection instanceof GapCursorSelection) {
145
- var _state$selection = state.selection,
146
- $from = _state$selection.$from,
147
- $anchor = _state$selection.$anchor;
148
- var tr = state.tr;
149
- if (isBackward(dir)) {
150
- if (state.selection.side === 'left') {
151
- tr.setSelection(new GapCursorSelection($anchor, Side.RIGHT));
152
- if (dispatch) {
153
- dispatch(tr);
154
- }
155
- return true;
156
- }
157
- tr = removeNodeBefore(state.tr);
158
- } else if ($from.nodeAfter) {
159
- tr = tr.delete($from.pos, $from.pos + $from.nodeAfter.nodeSize);
160
- }
161
- if (dispatch) {
162
- dispatch(tr.setSelection(Selection.near(tr.doc.resolve(tr.mapping.map(state.selection.$from.pos)))).scrollIntoView());
163
- }
164
- return true;
165
- }
166
- return false;
167
- };
168
- };
169
- export var setGapCursorAtPos = function setGapCursorAtPos(position) {
170
- var side = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Side.LEFT;
171
- return function (state, dispatch) {
172
- // @see ED-6231
173
- if (position > state.doc.content.size) {
174
- return false;
175
- }
176
- var $pos = state.doc.resolve(position);
177
- if (GapCursorSelection.valid($pos)) {
178
- if (dispatch) {
179
- dispatch(state.tr.setSelection(new GapCursorSelection($pos, side)));
180
- }
181
- return true;
182
- }
183
- return false;
184
- };
185
- };
186
-
187
- // This function captures clicks outside of the ProseMirror contentEditable area
188
- // see also description of "handleClick" in gap-cursor pm-plugin
189
- var captureCursorCoords = function captureCursorCoords(event, editorRef, posAtCoords, tr) {
190
- var rect = editorRef.getBoundingClientRect();
191
-
192
- // capture clicks before the first block element
193
- if (event.clientY < rect.top) {
194
- return {
195
- position: 0,
196
- side: Side.LEFT
197
- };
198
- }
199
- if (rect.left > 0) {
200
- // calculate start position of a node that is vertically at the same level
201
- var _coords = posAtCoords({
202
- left: rect.left,
203
- top: event.clientY
204
- });
205
- if (_coords && _coords.inside > -1) {
206
- var $from = tr.doc.resolve(_coords.inside);
207
- var start = $from.before(1);
208
- var side = event.clientX < rect.left ? Side.LEFT : Side.RIGHT;
209
- var position;
210
- if (side === Side.LEFT) {
211
- position = start;
212
- } else {
213
- var node = tr.doc.nodeAt(start);
214
- if (node) {
215
- position = start + node.nodeSize;
216
- }
217
- }
218
- return {
219
- position: position,
220
- side: side
221
- };
222
- }
223
- }
224
- return null;
225
- };
226
- export var setSelectionTopLevelBlocks = function setSelectionTopLevelBlocks(tr, event, editorRef, posAtCoords, editorFocused) {
227
- var cursorCoords = captureCursorCoords(event, editorRef, posAtCoords, tr);
228
- if (!cursorCoords) {
229
- return;
230
- }
231
- var $pos = cursorCoords.position !== undefined ? tr.doc.resolve(cursorCoords.position) : null;
232
- if ($pos === null) {
233
- return;
234
- }
235
- var isGapCursorAllowed = cursorCoords.side === Side.LEFT ? isValidTargetNode($pos.nodeAfter) : isValidTargetNode($pos.nodeBefore);
236
- if (isGapCursorAllowed && GapCursorSelection.valid($pos)) {
237
- // 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
238
- if (tr.selection instanceof GapCursorSelection) {
239
- tr.setSelection(Selection.near($pos));
240
- } else {
241
- tr.setSelection(new GapCursorSelection($pos, cursorCoords.side));
242
- }
243
- }
244
- // try to set text selection if the editor isnt focused
245
- // if the editor is focused, we are most likely dragging a selection outside.
246
- else if (editorFocused === false) {
247
- var selectionTemp = Selection.findFrom($pos, cursorCoords.side === Side.LEFT ? 1 : -1, true);
248
- if (selectionTemp) {
249
- tr.setSelection(selectionTemp);
250
- }
251
- }
252
- };
253
- export var setCursorForTopLevelBlocks = function setCursorForTopLevelBlocks(event, editorRef, posAtCoords, editorFocused) {
254
- return function (state, dispatch) {
255
- var tr = state.tr;
256
- setSelectionTopLevelBlocks(tr, event, editorRef, posAtCoords, editorFocused);
257
- if (tr.selectionSet && dispatch) {
258
- dispatch(tr);
259
- return true;
260
- }
261
- return false;
262
- };
263
- };
264
- export var hasGapCursorPlugin = function hasGapCursorPlugin(state) {
265
- return Boolean(gapCursorPluginKey.get(state));
266
- };
@@ -1,15 +0,0 @@
1
- export var 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,10 +0,0 @@
1
- import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
- var _templateObject, _templateObject2;
3
- import { css, keyframes } from '@emotion/react';
4
- var gapCursorBlink = keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n from, to {\n opacity: 0;\n }\n 50% {\n opacity: 1;\n }\n"])));
5
- export var hideCaretModifier = 'ProseMirror-hide-gapcursor';
6
- var gapCursor = '.ProseMirror-gapcursor';
7
- var prosemirrorwidget = '.ProseMirror-widget';
8
- var wrapLeft = '[layout="wrap-left"]';
9
- var wrapRight = '[layout="wrap-right"]';
10
- export var gapCursorStyles = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n /* =============== GAP CURSOR ================== */\n .ProseMirror {\n &.", " {\n caret-color: transparent;\n }\n\n ", " {\n display: none;\n pointer-events: none;\n position: relative;\n\n & span {\n caret-color: transparent;\n position: absolute;\n height: 100%;\n width: 100%;\n display: block;\n }\n\n & span::after {\n animation: 1s ", " step-end infinite;\n border-left: 1px solid;\n content: '';\n display: block;\n position: absolute;\n top: 0;\n height: 100%;\n }\n &.-left span::after {\n left: -3px;\n }\n &.-right span::after {\n right: -3px;\n }\n & span[layout='full-width'],\n & span[layout='wide'],\n & span[layout='fixed-width'] {\n margin-left: 50%;\n transform: translateX(-50%);\n }\n &", " {\n float: right;\n }\n\n /* fix vertical alignment of gap cursor */\n &:first-of-type + ul,\n &:first-of-type + span + ul,\n &:first-of-type + ol,\n &:first-of-type + span + ol,\n &:first-of-type + pre,\n &:first-of-type + span + pre,\n &:first-of-type + blockquote,\n &:first-of-type + span + blockquote {\n margin-top: 0;\n }\n }\n &.ProseMirror-focused ", " {\n display: block;\n border-color: transparent;\n }\n }\n\n /* This hack below is for two images aligned side by side */\n ", "", " + span + ", ",\n ", "", " + span + ", ",\n ", " + ", " + ", ",\n ", " + ", " + span + ", ",\n ", " + ", " + ", ",\n ", " + ", " + span + ", ",\n ", " + ", " + ", ",\n ", " + ", " + span ", ",\n ", " + ", " + ", ",\n ", " + ", " + span + ", ",\n ", " + ", " {\n clear: none;\n }\n\n ", " + ", " + ", " > div,\n ", " + ", " + span + ", " > div,\n ", " + ", " + ", " > div,\n ", " + ", " + span + ", " > div,\n ", " + ", " + ", " > div,\n ", " + ", " + span + ", " > div,\n ", " + ", " + ", " > div,\n ", " + ", " + span + ", " > div {\n margin-right: 0;\n margin-left: 0;\n margin-bottom: 0;\n }\n\n ", " + ", ",\n ", " + ", " {\n float: left;\n }\n\n ", " + ", " + span + ", "::after,\n ", " + ", " + span + ", "::after,\n ", " + ", " + ", "::after,\n ", " + ", " + span + ", "::after,\n ", " + ", " + ", "::after,\n ", " + ", " + span + ", "::after {\n visibility: hidden;\n display: block;\n font-size: 0;\n content: ' ';\n clear: both;\n height: 0;\n }\n\n ", " + ", " + ", " + *,\n ", " + ", " + ", " + span + *,\n ", " + ", " + ", " + *,\n ", " + ", " + ", " + span + *,\n ", " + ", " + span + ", " + *,\n ", " + ", " + span + ", " + *,\n ", " + ", " + span + ", " + *,\n ", " + ", " + span + ", " + *,\n ", " + ", " + ", " + * > *,\n ", " + ", " + ", " + span + * > *,\n ", " + ", " + ", " + * > *,\n ", " + ", " + ", " + span + * > *,\n ", " + ", " + span + ", " + * > *,\n ", " + ", " + span + ", " + * > *,\n ", " + ", " + span + ", " + * > *,\n ", " + ", " + span + ", " + * > *,\n ", " + ", " + *,\n ", " + ", " + span + * {\n margin-top: 0;\n }\n"])), hideCaretModifier, gapCursor, gapCursorBlink, wrapRight, gapCursor, gapCursor, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapLeft, gapCursor, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapRight, wrapLeft, gapCursor, wrapRight, gapCursor, gapCursor, wrapLeft, wrapRight, gapCursor, wrapRight, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, gapCursor, wrapLeft, wrapRight, gapCursor, wrapRight, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, wrapRight, gapCursor, wrapLeft, wrapLeft, gapCursor, wrapRight, wrapRight, gapCursor, wrapLeft, gapCursor, wrapLeft, wrapRight, gapCursor, wrapRight, wrapLeft, prosemirrorwidget, gapCursor, prosemirrorwidget, gapCursor);
@@ -1 +0,0 @@
1
- export { isIgnored } from '@atlaskit/editor-common/selection';
@@ -1 +0,0 @@
1
- export { isValidTargetNode } from '@atlaskit/editor-common/selection';
@@ -1,97 +0,0 @@
1
- import _toArray from "@babel/runtime/helpers/toArray";
2
- import { getLayoutModeFromTargetNode, isLeftCursor, getComputedStyleForLayoutMode } from '../utils';
3
- import { Side } from '@atlaskit/editor-common/selection';
4
-
5
- /**
6
- * We have a couple of nodes that require us to compute style
7
- * on different elements, ideally all nodes should be able to
8
- * compute the appropriate styles based on their wrapper.
9
- */
10
- var nestedCases = {
11
- 'tableView-content-wrap': 'table',
12
- 'mediaSingleView-content-wrap': '.rich-media-item',
13
- 'bodiedExtensionView-content-wrap': '.extension-container',
14
- 'embedCardView-content-wrap': '.rich-media-item',
15
- 'datasourceView-content-wrap': '.datasourceView-content-inner-wrap'
16
- };
17
- var computeNestedStyle = function computeNestedStyle(dom) {
18
- var foundKey = Object.keys(nestedCases).find(function (className) {
19
- return dom.classList.contains(className);
20
- });
21
- var nestedSelector = foundKey && nestedCases[foundKey];
22
- if (nestedSelector) {
23
- var nestedElement = dom.querySelector(nestedSelector);
24
- if (nestedElement) {
25
- return window.getComputedStyle(nestedElement);
26
- }
27
- }
28
- };
29
- var measureHeight = function measureHeight(style) {
30
- return measureValue(style, ['height', 'padding-top', 'padding-bottom', 'border-top-width', 'border-bottom-width']);
31
- };
32
- var measureWidth = function measureWidth(style) {
33
- return measureValue(style, ['width', 'padding-left', 'padding-right', 'border-left-width', 'border-right-width']);
34
- };
35
- var measureValue = function measureValue(style, measureValues) {
36
- var _measureValues = _toArray(measureValues),
37
- base = _measureValues[0],
38
- contentBoxValues = _measureValues.slice(1);
39
- var measures = [style.getPropertyValue(base)];
40
- var boxSizing = style.getPropertyValue('box-sizing');
41
- if (boxSizing === 'content-box') {
42
- contentBoxValues.forEach(function (value) {
43
- measures.push(style.getPropertyValue(value));
44
- });
45
- }
46
- var result = 0;
47
- for (var i = 0; i < measures.length; i++) {
48
- result += parseFloat(measures[i]);
49
- }
50
- return result;
51
- };
52
- var mutateElementStyle = function mutateElementStyle(element, style, side) {
53
- element.style.transform = style.getPropertyValue('transform');
54
- if (isLeftCursor(side)) {
55
- element.style.width = style.getPropertyValue('width');
56
- element.style.marginLeft = style.getPropertyValue('margin-left');
57
- } else {
58
- var marginRight = parseFloat(style.getPropertyValue('margin-right'));
59
- if (marginRight > 0) {
60
- element.style.marginLeft = "-".concat(Math.abs(marginRight), "px");
61
- } else {
62
- element.style.paddingRight = "".concat(Math.abs(marginRight), "px");
63
- }
64
- }
65
- };
66
- export var toDOM = function toDOM(view, getPos) {
67
- var selection = view.state.selection;
68
- var $from = selection.$from,
69
- side = selection.side;
70
- var isRightCursor = side === Side.RIGHT;
71
- var node = isRightCursor ? $from.nodeBefore : $from.nodeAfter;
72
- var nodeStart = getPos();
73
- // @ts-ignore - [unblock prosemirror bump] nodeStart can be undefined
74
- var dom = view.nodeDOM(nodeStart);
75
- var element = document.createElement('span');
76
- element.className = "ProseMirror-gapcursor ".concat(isRightCursor ? '-right' : '-left');
77
- element.appendChild(document.createElement('span'));
78
- if (dom instanceof HTMLElement && element.firstChild) {
79
- var style = computeNestedStyle(dom) || window.getComputedStyle(dom);
80
- var gapCursor = element.firstChild;
81
- gapCursor.style.height = "".concat(measureHeight(style), "px");
82
- var layoutMode = node && getLayoutModeFromTargetNode(node);
83
-
84
- // TODO remove this table specific piece. need to figure out margin collapsing logic
85
- if (nodeStart !== 0 || layoutMode || (node === null || node === void 0 ? void 0 : node.type.name) === 'table') {
86
- gapCursor.style.marginTop = style.getPropertyValue('margin-top');
87
- }
88
- if (layoutMode) {
89
- gapCursor.setAttribute('layout', layoutMode);
90
- var breakoutModeStyle = getComputedStyleForLayoutMode(dom, node, style);
91
- gapCursor.style.width = "".concat(measureWidth(breakoutModeStyle), "px");
92
- } else {
93
- mutateElementStyle(gapCursor, style, selection.side);
94
- }
95
- }
96
- return element;
97
- };