@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,128 +0,0 @@
1
- import { TableSharedCssClassName, UnsupportedSharedCssClassName } from '@atlaskit/editor-common/styles';
2
- import { Side } from './selection';
3
- import { CAPTION_PLACEHOLDER_ID } from '@atlaskit/editor-common/media-single';
4
- export var isLeftCursor = function isLeftCursor(side) {
5
- return side === Side.LEFT;
6
- };
7
- export function getMediaNearPos(doc, $pos, schema) {
8
- var dir = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
9
- var $currentPos = $pos;
10
- var currentNode = null;
11
- var _schema$nodes = schema.nodes,
12
- mediaSingle = _schema$nodes.mediaSingle,
13
- media = _schema$nodes.media,
14
- mediaGroup = _schema$nodes.mediaGroup;
15
- do {
16
- $currentPos = doc.resolve(dir === -1 ? $currentPos.before() : $currentPos.after());
17
- if (!$currentPos) {
18
- return null;
19
- }
20
- currentNode = (dir === -1 ? $currentPos.nodeBefore : $currentPos.nodeAfter) || $currentPos.parent;
21
- if (!currentNode || currentNode.type === schema.nodes.doc) {
22
- return null;
23
- }
24
- if (currentNode.type === mediaSingle || currentNode.type === media || currentNode.type === mediaGroup) {
25
- return currentNode;
26
- }
27
- } while ($currentPos.depth > 0);
28
- return null;
29
- }
30
- export var isTextBlockNearPos = function isTextBlockNearPos(doc, schema, $pos, dir) {
31
- var $currentPos = $pos;
32
- var currentNode = dir === -1 ? $currentPos.nodeBefore : $currentPos.nodeAfter;
33
-
34
- // If next node is a text or a text block bail out early.
35
- if (currentNode && (currentNode.isTextblock || currentNode.isText)) {
36
- return true;
37
- }
38
- while ($currentPos.depth > 0) {
39
- $currentPos = doc.resolve(dir === -1 ? $currentPos.before() : $currentPos.after());
40
- if (!$currentPos) {
41
- return false;
42
- }
43
- currentNode = (dir === -1 ? $currentPos.nodeBefore : $currentPos.nodeAfter) || $currentPos.parent;
44
- if (!currentNode || currentNode.type === schema.nodes.doc) {
45
- return false;
46
- }
47
- if (currentNode.isTextblock) {
48
- return true;
49
- }
50
- }
51
- var childNode = currentNode;
52
- while (childNode && childNode.firstChild) {
53
- childNode = childNode.firstChild;
54
- if (childNode && (childNode.isTextblock || childNode.isText)) {
55
- return true;
56
- }
57
- }
58
- return false;
59
- };
60
- export function getLayoutModeFromTargetNode(node) {
61
- var layout;
62
- if (node.attrs.layout) {
63
- layout = node.attrs.layout;
64
- }
65
- if (node.marks && node.marks.length) {
66
- layout = (node.marks.find(function (mark) {
67
- return mark.type.name === 'breakout';
68
- }) || {
69
- attrs: {
70
- mode: ''
71
- }
72
- }).attrs.mode;
73
- }
74
- if (node.type.name === 'table' && node.attrs.width) {
75
- layout = 'fixed-width';
76
- }
77
- if (['wide', 'full-width', 'fixed-width'].indexOf(layout) === -1) {
78
- return '';
79
- }
80
- return layout;
81
- }
82
- export var isIgnoredClick = function isIgnoredClick(elem) {
83
- if (elem.nodeName === 'BUTTON' || elem.closest('button')) {
84
- return true;
85
- }
86
-
87
- // check if we're clicking an image caption placeholder
88
- if (elem.closest("[data-id=\"".concat(CAPTION_PLACEHOLDER_ID, "\"]"))) {
89
- return true;
90
- }
91
-
92
- // check if target node has a parent table node
93
- var tableWrap;
94
- var node = elem;
95
- while (node) {
96
- if (node.className && (node.getAttribute('class') || '').indexOf(TableSharedCssClassName.TABLE_CONTAINER) > -1) {
97
- tableWrap = node;
98
- break;
99
- }
100
- node = node.parentNode;
101
- }
102
- if (tableWrap) {
103
- var rowControls = tableWrap.querySelector(".".concat(TableSharedCssClassName.TABLE_ROW_CONTROLS_WRAPPER));
104
- var isColumnControlsDecoration = elem && elem.classList && elem.classList.contains(TableSharedCssClassName.TABLE_COLUMN_CONTROLS_DECORATIONS);
105
- return rowControls && rowControls.contains(elem) || isColumnControlsDecoration;
106
- }
107
-
108
- // Check if unsupported node selection
109
- // (without this, selection requires double clicking in FF due to posAtCoords differences)
110
- if (elem.closest(".".concat(UnsupportedSharedCssClassName.BLOCK_CONTAINER))) {
111
- return true;
112
- }
113
- return false;
114
- };
115
-
116
- /*
117
- Calculates custom style for breakout mode
118
- Mainly to handle table width to include the numbered column width as well
119
- */
120
- export var getComputedStyleForLayoutMode = function getComputedStyleForLayoutMode(dom, node, style) {
121
- if (node && node.type.name === 'table') {
122
- var tableContainer = dom.querySelector('.pm-table-container');
123
- if (tableContainer) {
124
- return window.getComputedStyle(tableContainer);
125
- }
126
- }
127
- return style;
128
- };
@@ -1,2 +0,0 @@
1
- export { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
2
- export { setCursorForTopLevelBlocks, setSelectionTopLevelBlocks, hasGapCursorPlugin } from './gap-cursor/actions';
@@ -1,58 +0,0 @@
1
- import { createPlugin } from './pm-plugins/selection-main';
2
- import { selectionPluginKey } from './types';
3
- import selectionKeymapPlugin from './pm-plugins/keymap';
4
- import gapCursorPlugin from './pm-plugins/gap-cursor-main';
5
- import { gapCursorPluginKey } from './pm-plugins/gap-cursor-plugin-key';
6
- import gapCursorKeymapPlugin from './pm-plugins/gap-cursor-keymap';
7
- import { selectNearNode } from './commands';
8
- var displayGapCursor = function displayGapCursor(toggle) {
9
- return function (_ref) {
10
- var tr = _ref.tr;
11
- return tr.setMeta(gapCursorPluginKey, {
12
- displayGapCursor: toggle
13
- });
14
- };
15
- };
16
- export var selectionPlugin = function selectionPlugin(_ref2) {
17
- var options = _ref2.config;
18
- return {
19
- name: 'selection',
20
- commands: {
21
- displayGapCursor: displayGapCursor,
22
- selectNearNode: selectNearNode
23
- },
24
- getSharedState: function getSharedState(editorState) {
25
- if (!editorState) {
26
- return undefined;
27
- }
28
- var pluginState = selectionPluginKey.getState(editorState);
29
- return {
30
- selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode
31
- };
32
- },
33
- pmPlugins: function pmPlugins() {
34
- return [{
35
- name: 'selection',
36
- plugin: function plugin(_ref3) {
37
- var dispatch = _ref3.dispatch,
38
- dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
39
- return createPlugin(dispatch, dispatchAnalyticsEvent, options);
40
- }
41
- }, {
42
- name: 'selectionKeymap',
43
- plugin: selectionKeymapPlugin
44
- }, {
45
- name: 'gapCursorKeymap',
46
- plugin: function plugin() {
47
- return gapCursorKeymapPlugin();
48
- }
49
- }, {
50
- name: 'gapCursor',
51
- plugin: function plugin() {
52
- return gapCursorPlugin;
53
- }
54
- }];
55
- }
56
- };
57
- };
58
- export default selectionPlugin;
@@ -1,43 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
3
- 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) { _defineProperty(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; }
4
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
7
- import { pluginFactory } from '@atlaskit/editor-common/utils';
8
- import { reducer } from './reducer';
9
- import { selectionPluginKey } from './types';
10
- import { getDecorations, isSelectableContainerNode } from './utils';
11
- var handleDocChanged = function handleDocChanged(tr, pluginState) {
12
- // in some collab edge cases mapping decorations could throw an error
13
- try {
14
- if (pluginState.decorationSet.find().length === 0 && (!tr.selectionSet || getDecorations(tr).find().length === 0)) {
15
- return pluginState;
16
- }
17
- var decorationSet = pluginState.decorationSet.map(tr.mapping, tr.doc);
18
- return _objectSpread(_objectSpread({}, pluginState), {}, {
19
- decorationSet: decorationSet
20
- });
21
- } catch (error) {
22
- return _objectSpread(_objectSpread({}, pluginState), {}, {
23
- decorationSet: DecorationSet.empty
24
- });
25
- }
26
- };
27
- var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
28
- // Reset relative selection pos when user clicks to select a node
29
- if ((tr.selection instanceof NodeSelection && isSelectableContainerNode(tr.selection.node) || tr.selection instanceof CellSelection) && !tr.getMeta(selectionPluginKey)) {
30
- return _objectSpread(_objectSpread({}, pluginState), {}, {
31
- selectionRelativeToNode: undefined
32
- });
33
- }
34
- return pluginState;
35
- };
36
- var _pluginFactory = pluginFactory(selectionPluginKey, reducer, {
37
- onDocChanged: handleDocChanged,
38
- onSelectionChanged: handleSelectionChanged
39
- }),
40
- createCommand = _pluginFactory.createCommand,
41
- getPluginState = _pluginFactory.getPluginState,
42
- createPluginState = _pluginFactory.createPluginState;
43
- export { createCommand, getPluginState, createPluginState };
@@ -1,86 +0,0 @@
1
- import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- function isNodeContentEmpty(maybeNode) {
3
- return (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.content.size) === 0 || (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.textContent) === '';
4
- }
5
- function findEmptySelectableParentNodePosition($pos, isValidPosition) {
6
- var doc = $pos.doc;
7
- if ($pos.pos + 1 > doc.content.size) {
8
- return null;
9
- }
10
- if ($pos.nodeBefore !== null) {
11
- if (isValidPosition($pos)) {
12
- return $pos;
13
- }
14
-
15
- // We can not use `$pos.before()` because ProseMirror throws an error when depth is zero.
16
- var currentPosIndex = $pos.index();
17
- if (currentPosIndex === 0) {
18
- return null;
19
- }
20
- var previousIndex = currentPosIndex - 1;
21
- var $previousPos = $pos.doc.resolve($pos.posAtIndex(previousIndex));
22
- if (isValidPosition($previousPos)) {
23
- return $previousPos;
24
- }
25
- return null;
26
- }
27
- if (isValidPosition($pos)) {
28
- return $pos;
29
- }
30
- var positionLevelUp = $pos.before();
31
- var resolvedPositionLevelUp = doc.resolve(positionLevelUp);
32
- return findEmptySelectableParentNodePosition(resolvedPositionLevelUp, isValidPosition);
33
- }
34
- var checkPositionNode = function checkPositionNode($pos) {
35
- var maybeNode = $pos.nodeAfter;
36
- if (!maybeNode || !maybeNode.isBlock) {
37
- return false;
38
- }
39
- if (maybeNode.isAtom) {
40
- return true;
41
- }
42
- return isNodeContentEmpty(maybeNode) && NodeSelection.isSelectable(maybeNode);
43
- };
44
- function findNextSelectionPosition(_ref) {
45
- var $targetHead = _ref.$targetHead,
46
- $anchor = _ref.$anchor,
47
- doc = _ref.doc;
48
- var direction = $anchor.pos < $targetHead.pos ? 'down' : 'up';
49
- var maybeNextPosition = findEmptySelectableParentNodePosition($targetHead, checkPositionNode);
50
- if (maybeNextPosition && maybeNextPosition.nodeAfter) {
51
- var nodeAfter = maybeNextPosition.nodeAfter;
52
- var pos = maybeNextPosition.pos;
53
- var nextPositionToSelect = direction === 'down' ? Math.min(nodeAfter.nodeSize + pos, doc.content.size) : Math.max(pos, 0);
54
- return doc.resolve(nextPositionToSelect);
55
- }
56
- return null;
57
- }
58
- export var onCreateSelectionBetween = function onCreateSelectionBetween(view, $anchor, $head) {
59
- var _$head$parent, _$head$parent2;
60
- if ($anchor.pos === $head.pos) {
61
- return null;
62
- }
63
- if ($anchor.depth === $head.depth && $anchor.sameParent($head)) {
64
- return null;
65
- }
66
-
67
- // If the head is targeting a paragraph on root, then let ProseMirror handle the text selection
68
- if ($head.depth === 1 && ((_$head$parent = $head.parent) === null || _$head$parent === void 0 ? void 0 : _$head$parent.type.name) === 'paragraph') {
69
- return null;
70
- }
71
-
72
- // If head is at the beginning of a non-empty textblock, let ProseMirror handle the text selection
73
- if ((_$head$parent2 = $head.parent) !== null && _$head$parent2 !== void 0 && _$head$parent2.isTextblock && !isNodeContentEmpty($head.parent) && $head.parentOffset === 0) {
74
- return null;
75
- }
76
- var $nextHeadPosition = findNextSelectionPosition({
77
- $targetHead: $head,
78
- $anchor: $anchor,
79
- doc: view.state.doc
80
- });
81
- if (!$nextHeadPosition) {
82
- return null;
83
- }
84
- var forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, $nextHeadPosition.pos);
85
- return forcedTextSelection;
86
- };
@@ -1,110 +0,0 @@
1
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
-
3
- /*
4
- * The way expand was built, no browser reconize selection on it.
5
- * For instance, when a selection going to a "collapsed" expand
6
- * the browser will try to send the cursor to inside the expand content (wrong),
7
- * this behavior is caused because the expand content is never true hidden
8
- * we just set the height to 1px.
9
- *
10
- * So, we need to capture a possible selection event
11
- * when a collapsed exxpand is the next node in the common depth.
12
- * If that is true, we create a new TextSelection and stop the event bubble
13
- */
14
- var isCollpasedExpand = function isCollpasedExpand(node) {
15
- return Boolean(node && ['expand', 'nestedExpand'].includes(node.type.name) && !node.attrs.__expanded);
16
- };
17
-
18
- /**
19
- * ED-18072 - Cannot shift + arrow past bodied extension if it is not empty
20
- */
21
- var isBodiedExtension = function isBodiedExtension(node) {
22
- return Boolean(node && ['bodiedExtension'].includes(node.type.name));
23
- };
24
-
25
- /**
26
- * ED-19861 - [Regression] keyboard selections within action items are unpredicatable
27
- * Table was added to the list of problematic nodes because the desired behaviour when Shift+Up from outside the
28
- * table is to select the table node itself, rather than the table cell content. Previously this behaviour was handled
29
- * in `packages/editor/editor-core/src/plugins/selection/pm-plugins/events/create-selection-between.ts` but there was
30
- * a bug in `create-selection-between` which after fixing the bug that code was no longer handling table selection
31
- * correctly, so to fix that table was added here.
32
- */
33
- var isTable = function isTable(node) {
34
- return Boolean(node && ['table'].includes(node.type.name));
35
- };
36
- var isProblematicNode = function isProblematicNode(node) {
37
- return isCollpasedExpand(node) || isBodiedExtension(node) || isTable(node);
38
- };
39
- var findFixedProblematicNodePosition = function findFixedProblematicNodePosition(doc, $head, direction) {
40
- if ($head.pos === 0 || $head.depth === 0) {
41
- return null;
42
- }
43
- if (direction === 'up') {
44
- var pos = $head.before();
45
- var $posResolved = $head.doc.resolve(pos);
46
- var maybeProblematicNode = $posResolved.nodeBefore;
47
- if (maybeProblematicNode && isProblematicNode(maybeProblematicNode)) {
48
- var nodeSize = maybeProblematicNode.nodeSize;
49
- var nodeStartPosition = pos - nodeSize;
50
-
51
- // ($head.pos - 1) will correspond to (nodeStartPosition + nodeSize) when we are at the start of the text node
52
- var isAtEndOfProblematicNode = $head.pos - 1 === nodeStartPosition + nodeSize;
53
- if (isAtEndOfProblematicNode) {
54
- var startPosNode = Math.max(nodeStartPosition, 0);
55
- var $startPosNode = $head.doc.resolve(Math.min(startPosNode, $head.doc.content.size));
56
- return $startPosNode;
57
- }
58
- }
59
- }
60
- if (direction === 'down') {
61
- var _pos = $head.after();
62
- var _maybeProblematicNode = doc.nodeAt(_pos);
63
- if (_maybeProblematicNode && isProblematicNode(_maybeProblematicNode) && $head.pos + 1 === _pos) {
64
- var _nodeSize = _maybeProblematicNode.nodeSize;
65
- var nodePosition = _pos + _nodeSize;
66
- var _startPosNode = Math.max(nodePosition, 0);
67
- var _$startPosNode = $head.doc.resolve(Math.min(_startPosNode, $head.doc.content.size));
68
- return _$startPosNode;
69
- }
70
- }
71
- return null;
72
- };
73
- export var onKeydown = function onKeydown(view, event) {
74
- /*
75
- * This workaround is needed for some specific situations.
76
- * - expand collapse
77
- * - bodied extension
78
- */
79
- if (!(event instanceof KeyboardEvent)) {
80
- return false;
81
- }
82
- if (!event.shiftKey || event.ctrlKey || event.metaKey) {
83
- return false;
84
- }
85
- if (!['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.key)) {
86
- return false;
87
- }
88
- var _view$state = view.state,
89
- doc = _view$state.doc,
90
- _view$state$selection = _view$state.selection,
91
- $head = _view$state$selection.$head,
92
- $anchor = _view$state$selection.$anchor;
93
- if (event.key === 'ArrowRight' && $head.nodeAfter || event.key === 'ArrowLeft' && $head.nodeBefore) {
94
- return false;
95
- }
96
- var direction = ['ArrowLeft', 'ArrowUp', 'Home'].includes(event.key) ? 'up' : 'down';
97
- var $fixedProblematicNodePosition = findFixedProblematicNodePosition(doc, $head, direction);
98
- if ($fixedProblematicNodePosition) {
99
- // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
100
- var headOffset = event.key === 'ArrowLeft' ? -1 : 0;
101
- var head = $fixedProblematicNodePosition.pos + headOffset;
102
- var forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, head);
103
- var tr = view.state.tr;
104
- tr.setSelection(forcedTextSelection);
105
- view.dispatch(tr);
106
- event.preventDefault();
107
- return true;
108
- }
109
- return false;
110
- };
@@ -1,40 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { bindKeymapWithCommand, insertNewLine, moveLeft, moveRight, moveUp, moveDown, backspace, deleteKey } from '@atlaskit/editor-common/keymaps';
3
- import { arrow, deleteNode } from '../gap-cursor/actions';
4
- import { Direction } from '../gap-cursor/direction';
5
- import { GapCursorSelection } from '../gap-cursor/selection';
6
- import { createParagraphNear } from '@atlaskit/editor-prosemirror/commands';
7
- export default function keymapPlugin() {
8
- var map = {};
9
- bindKeymapWithCommand(insertNewLine.common, function (state, dispatch, view) {
10
- var isInGapCursor = state.selection instanceof GapCursorSelection;
11
- // Only operate in gap cursor
12
- if (!isInGapCursor) {
13
- return false;
14
- }
15
- return createParagraphNear(state, dispatch);
16
- }, map);
17
- bindKeymapWithCommand(moveLeft.common, function (state, dispatch, view) {
18
- var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
19
- return arrow(Direction.LEFT, endOfTextblock)(state, dispatch, view);
20
- }, map);
21
- bindKeymapWithCommand(moveRight.common, function (state, dispatch, view) {
22
- var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
23
- return arrow(Direction.RIGHT, endOfTextblock)(state, dispatch);
24
- }, map);
25
- bindKeymapWithCommand(moveUp.common, function (state, dispatch, view) {
26
- var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
27
- return arrow(Direction.UP, endOfTextblock)(state, dispatch);
28
- }, map);
29
- bindKeymapWithCommand(moveDown.common, function (state, dispatch, view) {
30
- var endOfTextblock = view ? view.endOfTextblock.bind(view) : undefined;
31
- return arrow(Direction.DOWN, endOfTextblock)(state, dispatch);
32
- }, map);
33
-
34
- // default PM's Backspace doesn't handle removing block nodes when cursor is after it
35
- bindKeymapWithCommand(backspace.common, deleteNode(Direction.BACKWARD), map);
36
-
37
- // handle Delete key (remove node after the cursor)
38
- bindKeymapWithCommand(deleteKey.common, deleteNode(Direction.FORWARD), map);
39
- return keymap(map);
40
- }
@@ -1,154 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { findPositionOfNodeBefore } from '@atlaskit/editor-prosemirror/utils';
5
- import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
- import { hideCaretModifier } from '../gap-cursor/styles';
7
- import { GapCursorSelection, JSON_ID, Side as GapCursorSide, Side } from '../gap-cursor/selection';
8
- import { getLayoutModeFromTargetNode, isIgnoredClick } from '../gap-cursor/utils';
9
- import { toDOM } from '../gap-cursor/utils/place-gap-cursor';
10
- import { deleteNode, setGapCursorAtPos } from '../gap-cursor/actions';
11
- import { Direction } from '../gap-cursor/direction';
12
- import { gapCursorPluginKey } from './gap-cursor-plugin-key';
13
- var plugin = new SafePlugin({
14
- key: gapCursorPluginKey,
15
- state: {
16
- init: function init() {
17
- return {
18
- selectionIsGapCursor: false,
19
- displayGapCursor: true
20
- };
21
- },
22
- apply: function apply(tr, pluginState, _oldState, newState) {
23
- var _meta$displayGapCurso;
24
- var meta = tr.getMeta(gapCursorPluginKey);
25
- var selectionIsGapCursor = newState.selection instanceof GapCursorSelection;
26
- return {
27
- selectionIsGapCursor: selectionIsGapCursor,
28
- // only attempt to hide gap cursor if selection is gap cursor
29
- displayGapCursor: selectionIsGapCursor ? (_meta$displayGapCurso = meta === null || meta === void 0 ? void 0 : meta.displayGapCursor) !== null && _meta$displayGapCurso !== void 0 ? _meta$displayGapCurso : pluginState.displayGapCursor : true
30
- };
31
- }
32
- },
33
- view: function view(_view) {
34
- /**
35
- * If the selection is at the beginning of a document and is a NodeSelection,
36
- * convert to a GapCursor selection. This is to stop users accidentally replacing
37
- * the first node of a document by accident.
38
- */
39
- if (_view.state.selection.anchor === 0 && _view.state.selection instanceof NodeSelection) {
40
- // This is required otherwise the dispatch doesn't trigger in the correct place
41
- window.requestAnimationFrame(function () {
42
- _view.dispatch(_view.state.tr.setSelection(new GapCursorSelection(_view.state.doc.resolve(0), GapCursorSide.LEFT)));
43
- });
44
- }
45
- return {
46
- update: function update(view) {
47
- var _gapCursorPluginKey$g = gapCursorPluginKey.getState(view.state),
48
- selectionIsGapCursor = _gapCursorPluginKey$g.selectionIsGapCursor;
49
- /**
50
- * Starting with prosemirror-view 1.19.4, cursor wrapper that previously was hiding cursor doesn't exist:
51
- * https://github.com/ProseMirror/prosemirror-view/commit/4a56bc7b7e61e96ef879d1dae1014ede0fc09e43
52
- *
53
- * Because it was causing issues with RTL: https://github.com/ProseMirror/prosemirror/issues/948
54
- *
55
- * This is the work around which uses `caret-color: transparent` in order to hide regular caret,
56
- * when gap cursor is visible.
57
- *
58
- * Browser support is pretty good: https://caniuse.com/#feat=css-caret-color
59
- */
60
- view.dom.classList.toggle(hideCaretModifier, selectionIsGapCursor);
61
- }
62
- };
63
- },
64
- props: {
65
- decorations: function decorations(editorState) {
66
- var doc = editorState.doc,
67
- selection = editorState.selection;
68
- var _gapCursorPluginKey$g2 = gapCursorPluginKey.getState(editorState),
69
- displayGapCursor = _gapCursorPluginKey$g2.displayGapCursor;
70
- if (selection instanceof GapCursorSelection && displayGapCursor) {
71
- var $from = selection.$from,
72
- side = selection.side;
73
-
74
- // render decoration DOM node always to the left of the target node even if selection points to the right
75
- // otherwise positioning of the right gap cursor is a nightmare when the target node has a nodeView with vertical margins
76
- var position = selection.head;
77
- var isRightCursor = side === Side.RIGHT;
78
- if (isRightCursor && $from.nodeBefore) {
79
- var nodeBeforeStart = findPositionOfNodeBefore(selection);
80
- if (typeof nodeBeforeStart === 'number') {
81
- position = nodeBeforeStart;
82
- }
83
- }
84
- var node = isRightCursor ? $from.nodeBefore : $from.nodeAfter;
85
- var layoutMode = node && getLayoutModeFromTargetNode(node);
86
- return DecorationSet.create(doc, [Decoration.widget(position, toDOM, {
87
- key: "".concat(JSON_ID, "-").concat(side, "-").concat(layoutMode),
88
- side: layoutMode ? -1 : 0
89
- })]);
90
- }
91
- return null;
92
- },
93
- // render gap cursor only when its valid
94
- createSelectionBetween: function createSelectionBetween(view, $anchor, $head) {
95
- if (view && view.state && view.state.selection instanceof CellSelection) {
96
- // Do not show GapCursor when there is a CellSection happening
97
- return null;
98
- }
99
- if ($anchor.pos === $head.pos && GapCursorSelection.valid($head)) {
100
- return new GapCursorSelection($head);
101
- }
102
- return null;
103
- },
104
- handleClick: function handleClick(view, nodePos, event) {
105
- var _$pos$parent;
106
- var posAtCoords = view.posAtCoords({
107
- left: event.clientX,
108
- top: event.clientY
109
- });
110
- if (!posAtCoords || isIgnoredClick(event.target)) {
111
- return false;
112
- }
113
- var isInsideTheTarget = posAtCoords.pos === posAtCoords.inside;
114
- if (isInsideTheTarget) {
115
- return false;
116
- }
117
- var leftSideOffsetX = 20;
118
- var side = event.offsetX > leftSideOffsetX ? Side.RIGHT : Side.LEFT;
119
- var $pos = view.state.doc.resolve(nodePos);
120
- // In the new prosemirror-view posAtCoords is not returning a precise value for our media nodes
121
- if (((_$pos$parent = $pos.parent) === null || _$pos$parent === void 0 ? void 0 : _$pos$parent.type.name) === 'mediaSingle') {
122
- var $insidePos = view.state.doc.resolve(Math.max(posAtCoords.inside, 0));
123
- // We don't have GapCursors problems when the node target is inside the root level
124
- if ($insidePos.depth <= 1) {
125
- return false;
126
- }
127
- var mediaGapCursor = !$pos.nodeBefore ? $pos.before() : $pos.after();
128
- return setGapCursorAtPos(mediaGapCursor, side)(view.state, view.dispatch);
129
- }
130
- var docSize = view.state.doc.content.size;
131
- var nodeInside = posAtCoords.inside < 0 || posAtCoords.inside > docSize ? null : view.state.doc.nodeAt(posAtCoords.inside);
132
- if (nodeInside !== null && nodeInside !== void 0 && nodeInside.isAtom) {
133
- return false;
134
- }
135
- return setGapCursorAtPos(nodePos, side)(view.state, view.dispatch);
136
- },
137
- handleDOMEvents: {
138
- /**
139
- * Android composition events aren't handled well by Prosemirror
140
- * We've added a couple of beforeinput hooks to help PM out when trying to delete
141
- * certain nodes. We can remove these when PM has better composition support.
142
- * @see https://github.com/ProseMirror/prosemirror/issues/543
143
- */
144
- beforeinput: function beforeinput(view, event) {
145
- if (event.inputType === 'deleteContentBackward' && view.state.selection instanceof GapCursorSelection) {
146
- event.preventDefault();
147
- return deleteNode(Direction.BACKWARD)(view.state, view.dispatch);
148
- }
149
- return false;
150
- }
151
- }
152
- }
153
- });
154
- export default plugin;
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var gapCursorPluginKey = new PluginKey('gapCursorPlugin');
@@ -1,10 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { bindKeymapWithCommand, moveRight, moveLeft } from '@atlaskit/editor-common/keymaps';
3
- import { arrowRight, arrowLeft } from '../commands';
4
- function keymapPlugin() {
5
- var list = {};
6
- bindKeymapWithCommand(moveRight.common, arrowRight, list);
7
- bindKeymapWithCommand(moveLeft.common, arrowLeft, list);
8
- return keymap(list);
9
- }
10
- export default keymapPlugin;