@atlaskit/editor-core 187.9.0 → 187.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/plugins/emoji/commands/insert-emoji.js +31 -28
  3. package/dist/cjs/plugins/emoji/index.js +4 -3
  4. package/dist/cjs/plugins/emoji/pm-plugins/ascii-input-rules.js +23 -18
  5. package/dist/cjs/plugins/extension/pm-plugins/main.js +54 -9
  6. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
  7. package/dist/cjs/plugins/selection/pm-plugins/events/keydown.js +61 -25
  8. package/dist/cjs/version-wrapper.js +1 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/plugins/emoji/commands/insert-emoji.js +5 -5
  11. package/dist/es2019/plugins/emoji/index.js +6 -3
  12. package/dist/es2019/plugins/emoji/pm-plugins/ascii-input-rules.js +14 -11
  13. package/dist/es2019/plugins/extension/pm-plugins/main.js +50 -0
  14. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
  15. package/dist/es2019/plugins/selection/pm-plugins/events/keydown.js +60 -24
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/plugins/emoji/commands/insert-emoji.js +29 -27
  19. package/dist/esm/plugins/emoji/index.js +4 -3
  20. package/dist/esm/plugins/emoji/pm-plugins/ascii-input-rules.js +23 -18
  21. package/dist/esm/plugins/extension/pm-plugins/main.js +45 -0
  22. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +1 -1
  23. package/dist/esm/plugins/selection/pm-plugins/events/keydown.js +62 -25
  24. package/dist/esm/version-wrapper.js +1 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  27. package/dist/types/plugins/emoji/pm-plugins/ascii-input-rules.d.ts +3 -2
  28. package/dist/types/plugins/extension/pm-plugins/main.d.ts +1 -1
  29. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +1 -0
  30. package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  31. package/dist/types-ts4.5/plugins/emoji/pm-plugins/ascii-input-rules.d.ts +3 -2
  32. package/dist/types-ts4.5/plugins/extension/pm-plugins/main.d.ts +1 -1
  33. package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +1 -0
  34. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
+ import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
1
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { isSelectionAtStartOfNode, isSelectionAtEndOfNode } from '@atlaskit/editor-common/selection';
2
5
  import { createSelectionClickHandler } from '../../selection/utils';
3
6
  import ExtensionNodeView from '../nodeviews/extension';
4
7
  import { updateState, clearEditingContext } from '../commands';
@@ -163,6 +166,53 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
163
166
  },
164
167
  key: pluginKey,
165
168
  props: {
169
+ handleDOMEvents: {
170
+ /**
171
+ * ED-18072 - Cannot shift + arrow past bodied extension if it is not empty.
172
+ * This code is to handle the case where the selection starts inside or on the node and the user is trying to shift + arrow.
173
+ * For other part of the solution see code in: packages/editor/editor-core/src/plugins/selection/pm-plugins/events/keydown.ts
174
+ */
175
+ keydown: (view, event) => {
176
+ if (event instanceof KeyboardEvent && event.shiftKey && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
177
+ const {
178
+ schema,
179
+ selection,
180
+ selection: {
181
+ $head
182
+ },
183
+ doc,
184
+ tr
185
+ } = view.state;
186
+ const {
187
+ bodiedExtension
188
+ } = schema.nodes;
189
+ if (selection instanceof TextSelection || selection instanceof NodeSelection) {
190
+ const maybeBodiedExtension = selection instanceof TextSelection ? findParentNodeOfTypeClosestToPos($head, bodiedExtension) : findSelectedNodeOfType(bodiedExtension)(selection);
191
+ if (maybeBodiedExtension) {
192
+ const end = maybeBodiedExtension.pos + maybeBodiedExtension.node.nodeSize;
193
+ if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' && isSelectionAtStartOfNode($head, maybeBodiedExtension)) {
194
+ const anchor = end + 1;
195
+
196
+ // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
197
+ const headOffset = event.key === 'ArrowLeft' ? -1 : 0;
198
+ const head = maybeBodiedExtension.pos + headOffset;
199
+ const newSelection = TextSelection.create(doc, Math.max(anchor, selection.anchor), head);
200
+ view.dispatch(tr.setSelection(newSelection));
201
+ return true;
202
+ }
203
+ if (event.key === 'ArrowDown' || event.key === 'ArrowRight' && isSelectionAtEndOfNode($head, maybeBodiedExtension)) {
204
+ const anchor = maybeBodiedExtension.pos - 1;
205
+ const head = end + 1;
206
+ const newSelection = TextSelection.create(doc, Math.min(anchor, selection.anchor), head);
207
+ view.dispatch(tr.setSelection(newSelection));
208
+ return true;
209
+ }
210
+ }
211
+ }
212
+ }
213
+ return false;
214
+ }
215
+ },
166
216
  nodeViews: {
167
217
  // WARNING: referentiality-plugin also creates these nodeviews
168
218
  extension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
@@ -290,7 +290,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
290
290
  });
291
291
  _defineProperty(this, "handleSelectedEmoji", emojiId => {
292
292
  this.props.editorView.focus();
293
- insertEmoji(emojiId, INPUT_METHOD.PICKER)(this.props.editorView.state, this.props.editorView.dispatch);
293
+ insertEmoji(this.editorAnalyticsAPI)(emojiId, INPUT_METHOD.PICKER)(this.props.editorView.state, this.props.editorView.dispatch);
294
294
  this.toggleEmojiPicker();
295
295
  return true;
296
296
  });
@@ -1,36 +1,68 @@
1
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
+ */
2
14
  const isCollpasedExpand = node => {
3
15
  return Boolean(node && ['expand', 'nestedExpand'].includes(node.type.name) && !node.attrs.__expanded);
4
16
  };
5
- const findFixedProblematicNodePosition = ($pos, direction) => {
6
- if ($pos.pos === 0 || $pos.depth === 0) {
17
+
18
+ /**
19
+ * ED-18072 - Cannot shift + arrow past bodied extension if it is not empty
20
+ */
21
+ const isBodiedExtension = node => {
22
+ return Boolean(node && ['bodiedExtension'].includes(node.type.name));
23
+ };
24
+ const isProblematicNode = node => {
25
+ return isCollpasedExpand(node) || isBodiedExtension(node);
26
+ };
27
+ const findFixedProblematicNodePosition = (doc, $head, direction) => {
28
+ if ($head.pos === 0 || $head.depth === 0) {
7
29
  return null;
8
30
  }
9
- const pos = direction === 'up' ? $pos.before() : $pos.after();
10
- const $posResolved = $pos.doc.resolve(pos);
11
- const maybeExpandNode = direction === 'up' ? $posResolved.nodeBefore : $posResolved.nodeAfter;
12
- if (maybeExpandNode && isCollpasedExpand(maybeExpandNode)) {
13
- const nodeSize = maybeExpandNode.nodeSize;
14
- const expandPosition = direction === 'up' ? pos - nodeSize : pos + nodeSize;
15
- const startPosNode = Math.max(expandPosition, 0);
16
- const $startPosNode = $pos.doc.resolve(Math.min(startPosNode, $pos.doc.content.size));
17
- return $startPosNode;
31
+ if (direction === 'up') {
32
+ const pos = $head.before();
33
+ const $posResolved = $head.doc.resolve(pos);
34
+ const maybeProblematicNode = $posResolved.nodeBefore;
35
+ if (maybeProblematicNode && isProblematicNode(maybeProblematicNode)) {
36
+ const nodeSize = maybeProblematicNode.nodeSize;
37
+ const nodeStartPosition = pos - nodeSize;
38
+
39
+ // ($head.pos - 1) will correspond to (nodeStartPosition + nodeSize) when we are at the start of the text node
40
+ const isAtEndOfProblematicNode = $head.pos - 1 === nodeStartPosition + nodeSize;
41
+ if (isAtEndOfProblematicNode) {
42
+ const startPosNode = Math.max(nodeStartPosition, 0);
43
+ const $startPosNode = $head.doc.resolve(Math.min(startPosNode, $head.doc.content.size));
44
+ return $startPosNode;
45
+ }
46
+ }
47
+ }
48
+ if (direction === 'down') {
49
+ const pos = $head.after();
50
+ const maybeProblematicNode = doc.nodeAt(pos);
51
+ if (maybeProblematicNode && isProblematicNode(maybeProblematicNode) && $head.pos + 1 === pos) {
52
+ const nodeSize = maybeProblematicNode.nodeSize;
53
+ const nodePosition = pos + nodeSize;
54
+ const startPosNode = Math.max(nodePosition, 0);
55
+ const $startPosNode = $head.doc.resolve(Math.min(startPosNode, $head.doc.content.size));
56
+ return $startPosNode;
57
+ }
18
58
  }
19
59
  return null;
20
60
  };
21
61
  export const onKeydown = (view, event) => {
22
62
  /*
23
- * This workaround is needed for some specific situation with collapsed expand.
24
- *
25
- * The way expand was built, no browser reconize selection on it.
26
- * For instance, when a selection going to a "collapsed" expand
27
- * the browser will try to send the cursor to inside the expand content (wrong),
28
- * this behavior is caused because the expand content is never true hidden
29
- * we just set the height to 1px.
30
- *
31
- * So, we need to capture a possible selection event
32
- * when a collapsed exxpand is the next node in the common depth.
33
- * If that is true, we create a new TextSelection and stop the event bubble
63
+ * This workaround is needed for some specific situations.
64
+ * - expand collapse
65
+ * - bodied extension
34
66
  */
35
67
  if (!(event instanceof KeyboardEvent)) {
36
68
  return false;
@@ -42,6 +74,7 @@ export const onKeydown = (view, event) => {
42
74
  return false;
43
75
  }
44
76
  const {
77
+ doc,
45
78
  selection: {
46
79
  $head,
47
80
  $anchor
@@ -51,9 +84,12 @@ export const onKeydown = (view, event) => {
51
84
  return false;
52
85
  }
53
86
  const direction = ['ArrowLeft', 'ArrowUp', 'Home'].includes(event.key) ? 'up' : 'down';
54
- const $fixedProblematicNodePosition = findFixedProblematicNodePosition($head, direction);
87
+ const $fixedProblematicNodePosition = findFixedProblematicNodePosition(doc, $head, direction);
55
88
  if ($fixedProblematicNodePosition) {
56
- const forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, $fixedProblematicNodePosition.pos);
89
+ // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
90
+ const headOffset = event.key === 'ArrowLeft' ? -1 : 0;
91
+ const head = $fixedProblematicNodePosition.pos + headOffset;
92
+ const forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, head);
57
93
  const tr = view.state.tr;
58
94
  tr.setSelection(forcedTextSelection);
59
95
  view.dispatch(tr);
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.9.0";
2
+ export const version = "187.9.2";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.9.0",
3
+ "version": "187.9.2",
4
4
  "sideEffects": false
5
5
  }
@@ -4,33 +4,35 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
5
5
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
6
6
  import { Selection } from '@atlaskit/editor-prosemirror/state';
7
- import { addAnalytics, EVENT_TYPE, ACTION_SUBJECT_ID, ACTION_SUBJECT, ACTION } from '../../analytics';
8
- export function insertEmoji(emojiId, inputMethod) {
9
- return function (state, dispatch) {
10
- var emoji = state.schema.nodes.emoji;
11
- if (emoji && emojiId) {
12
- var node = emoji.createChecked(_objectSpread(_objectSpread({}, emojiId), {}, {
13
- text: emojiId.fallback || emojiId.shortName
14
- }));
15
- var textNode = state.schema.text(' ');
16
- if (dispatch) {
17
- var fragment = Fragment.fromArray([node, textNode]);
18
- var tr = safeInsert(fragment)(state.tr);
19
- if (inputMethod) {
20
- addAnalytics(state, tr, {
21
- action: ACTION.INSERTED,
22
- actionSubject: ACTION_SUBJECT.DOCUMENT,
23
- actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
24
- attributes: {
25
- inputMethod: inputMethod
26
- },
27
- eventType: EVENT_TYPE.TRACK
28
- });
7
+ import { EVENT_TYPE, ACTION_SUBJECT_ID, ACTION_SUBJECT, ACTION } from '@atlaskit/editor-common/analytics';
8
+ export var insertEmoji = function insertEmoji(editorAnalyticsAPI) {
9
+ return function (emojiId, inputMethod) {
10
+ return function (state, dispatch) {
11
+ var emoji = state.schema.nodes.emoji;
12
+ if (emoji && emojiId) {
13
+ var node = emoji.createChecked(_objectSpread(_objectSpread({}, emojiId), {}, {
14
+ text: emojiId.fallback || emojiId.shortName
15
+ }));
16
+ var textNode = state.schema.text(' ');
17
+ if (dispatch) {
18
+ var fragment = Fragment.fromArray([node, textNode]);
19
+ var tr = safeInsert(fragment)(state.tr);
20
+ if (inputMethod) {
21
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
22
+ action: ACTION.INSERTED,
23
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
24
+ actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
25
+ attributes: {
26
+ inputMethod: inputMethod
27
+ },
28
+ eventType: EVENT_TYPE.TRACK
29
+ })(tr);
30
+ }
31
+ dispatch(tr.setSelection(Selection.near(tr.doc.resolve(state.selection.$from.pos + fragment.size))));
29
32
  }
30
- dispatch(tr.setSelection(Selection.near(tr.doc.resolve(state.selection.$from.pos + fragment.size))));
33
+ return true;
31
34
  }
32
- return true;
33
- }
34
- return false;
35
+ return false;
36
+ };
35
37
  };
36
- }
38
+ };
@@ -174,10 +174,11 @@ var emojiPlugin = function emojiPlugin(options, api) {
174
174
  }, {
175
175
  name: 'emojiAsciiInputRule',
176
176
  plugin: function plugin(_ref6) {
177
+ var _api$dependencies$ana8;
177
178
  var schema = _ref6.schema,
178
179
  providerFactory = _ref6.providerFactory,
179
180
  featureFlags = _ref6.featureFlags;
180
- return asciiInputRulePlugin(schema, providerFactory, featureFlags);
181
+ return asciiInputRulePlugin(schema, providerFactory, featureFlags, api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions);
181
182
  }
182
183
  }];
183
184
  },
@@ -194,13 +195,13 @@ var emojiPlugin = function emojiPlugin(options, api) {
194
195
  return /*#__PURE__*/React.createElement(IconEmoji, null);
195
196
  },
196
197
  action: function action(insert, state) {
197
- var _api$dependencies$ana8;
198
+ var _api$dependencies$ana9;
198
199
  var tr = insert(undefined);
199
200
  openTypeAheadAtCursor({
200
201
  triggerHandler: typeAhead,
201
202
  inputMethod: INPUT_METHOD.QUICK_INSERT
202
203
  })(tr);
203
- api === null || api === void 0 ? void 0 : (_api$dependencies$ana8 = api.dependencies.analytics) === null || _api$dependencies$ana8 === void 0 ? void 0 : _api$dependencies$ana8.actions.attachAnalyticsEvent({
204
+ api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions.attachAnalyticsEvent({
204
205
  action: ACTION.INVOKED,
205
206
  actionSubject: ACTION_SUBJECT.TYPEAHEAD,
206
207
  actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_EMOJI,
@@ -10,12 +10,12 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
10
10
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
11
11
  import { createRule, createPlugin } from '@atlaskit/prosemirror-input-rules';
12
12
  import { leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
13
- import { addAnalytics, ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '../../analytics';
13
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, INPUT_METHOD, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
14
14
  var matcher;
15
- export function inputRulePlugin(schema, providerFactory, featureFlags) {
15
+ export function inputRulePlugin(schema, providerFactory, featureFlags, editorAnalyticsAPI) {
16
16
  if (schema.nodes.emoji && providerFactory) {
17
17
  initMatcher(providerFactory);
18
- var asciiEmojiRule = createRule(AsciiEmojiMatcher.REGEX, inputRuleHandler);
18
+ var asciiEmojiRule = createRule(AsciiEmojiMatcher.REGEX, inputRuleHandler(editorAnalyticsAPI));
19
19
  return createPlugin('emoji', [asciiEmojiRule]);
20
20
  }
21
21
  return;
@@ -33,17 +33,19 @@ function initMatcher(providerFactory) {
33
33
  };
34
34
  providerFactory.subscribe('emojiProvider', handleProvider);
35
35
  }
36
- function inputRuleHandler(state, matchParts, start, end) {
37
- if (!matcher) {
36
+ var inputRuleHandler = function inputRuleHandler(editorAnalyticsAPI) {
37
+ return function (state, matchParts, start, end) {
38
+ if (!matcher) {
39
+ return null;
40
+ }
41
+ var match = matcher.match(matchParts);
42
+ if (match) {
43
+ var transactionCreator = new AsciiEmojiTransactionCreator(state, match, start, end, editorAnalyticsAPI);
44
+ return transactionCreator.create();
45
+ }
38
46
  return null;
39
- }
40
- var match = matcher.match(matchParts);
41
- if (match) {
42
- var transactionCreator = new AsciiEmojiTransactionCreator(state, match, start, end);
43
- return transactionCreator.create();
44
- }
45
- return null;
46
- }
47
+ };
48
+ };
47
49
  var REGEX_LEADING_CAPTURE_INDEX = 1;
48
50
  var REGEX_EMOJI_LEADING_PARENTHESES = 2;
49
51
  var REGEX_EMOJI_ASCII_CAPTURE_INDEX = 3;
@@ -142,18 +144,20 @@ var RecordingAsciiEmojiMatcher = /*#__PURE__*/function (_AsciiEmojiMatcher) {
142
144
  return RecordingAsciiEmojiMatcher;
143
145
  }(AsciiEmojiMatcher);
144
146
  var AsciiEmojiTransactionCreator = /*#__PURE__*/function () {
145
- function AsciiEmojiTransactionCreator(state, match, start, end) {
147
+ function AsciiEmojiTransactionCreator(state, match, start, end, editorAnalyticsAPI) {
146
148
  _classCallCheck(this, AsciiEmojiTransactionCreator);
147
149
  this.state = state;
148
150
  this.match = match;
149
151
  this.start = start;
150
152
  this.end = end;
153
+ this.editorAnalyticsAPI = editorAnalyticsAPI;
151
154
  }
152
155
  _createClass(AsciiEmojiTransactionCreator, [{
153
156
  key: "create",
154
157
  value: function create() {
158
+ var _this$editorAnalytics;
155
159
  var tr = this.state.tr.replaceWith(this.from, this.to, this.createNodes());
156
- return addAnalytics(this.state, tr, {
160
+ (_this$editorAnalytics = this.editorAnalyticsAPI) === null || _this$editorAnalytics === void 0 ? void 0 : _this$editorAnalytics.attachAnalyticsEvent({
157
161
  action: ACTION.INSERTED,
158
162
  actionSubject: ACTION_SUBJECT.DOCUMENT,
159
163
  actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
@@ -161,7 +165,8 @@ var AsciiEmojiTransactionCreator = /*#__PURE__*/function () {
161
165
  inputMethod: INPUT_METHOD.ASCII
162
166
  },
163
167
  eventType: EVENT_TYPE.TRACK
164
- });
168
+ })(tr);
169
+ return tr;
165
170
  }
166
171
  }, {
167
172
  key: "from",
@@ -212,8 +217,8 @@ var AsciiEmojiTransactionCreator = /*#__PURE__*/function () {
212
217
  return AsciiEmojiTransactionCreator;
213
218
  }();
214
219
  export var stateKey = new PluginKey('asciiEmojiPlugin');
215
- var plugins = function plugins(schema, providerFactory, featureFlags) {
216
- return [inputRulePlugin(schema, providerFactory, featureFlags)].filter(function (plugin) {
220
+ var plugins = function plugins(schema, providerFactory, featureFlags, editorAnalyticsAPI) {
221
+ return [inputRulePlugin(schema, providerFactory, featureFlags, editorAnalyticsAPI)].filter(function (plugin) {
217
222
  return !!plugin;
218
223
  });
219
224
  };
@@ -1,7 +1,10 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _typeof from "@babel/runtime/helpers/typeof";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
+ import { isSelectionAtStartOfNode, isSelectionAtEndOfNode } from '@atlaskit/editor-common/selection';
5
8
  import { createSelectionClickHandler } from '../../selection/utils';
6
9
  import ExtensionNodeView from '../nodeviews/extension';
7
10
  import { updateState, clearEditingContext } from '../commands';
@@ -234,6 +237,48 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
234
237
  },
235
238
  key: pluginKey,
236
239
  props: {
240
+ handleDOMEvents: {
241
+ /**
242
+ * ED-18072 - Cannot shift + arrow past bodied extension if it is not empty.
243
+ * This code is to handle the case where the selection starts inside or on the node and the user is trying to shift + arrow.
244
+ * For other part of the solution see code in: packages/editor/editor-core/src/plugins/selection/pm-plugins/events/keydown.ts
245
+ */
246
+ keydown: function keydown(view, event) {
247
+ if (event instanceof KeyboardEvent && event.shiftKey && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
248
+ var _view$state = view.state,
249
+ schema = _view$state.schema,
250
+ selection = _view$state.selection,
251
+ $head = _view$state.selection.$head,
252
+ doc = _view$state.doc,
253
+ tr = _view$state.tr;
254
+ var bodiedExtension = schema.nodes.bodiedExtension;
255
+ if (selection instanceof TextSelection || selection instanceof NodeSelection) {
256
+ var maybeBodiedExtension = selection instanceof TextSelection ? findParentNodeOfTypeClosestToPos($head, bodiedExtension) : findSelectedNodeOfType(bodiedExtension)(selection);
257
+ if (maybeBodiedExtension) {
258
+ var end = maybeBodiedExtension.pos + maybeBodiedExtension.node.nodeSize;
259
+ if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' && isSelectionAtStartOfNode($head, maybeBodiedExtension)) {
260
+ var anchor = end + 1;
261
+
262
+ // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
263
+ var headOffset = event.key === 'ArrowLeft' ? -1 : 0;
264
+ var head = maybeBodiedExtension.pos + headOffset;
265
+ var newSelection = TextSelection.create(doc, Math.max(anchor, selection.anchor), head);
266
+ view.dispatch(tr.setSelection(newSelection));
267
+ return true;
268
+ }
269
+ if (event.key === 'ArrowDown' || event.key === 'ArrowRight' && isSelectionAtEndOfNode($head, maybeBodiedExtension)) {
270
+ var _anchor = maybeBodiedExtension.pos - 1;
271
+ var _head = end + 1;
272
+ var _newSelection = TextSelection.create(doc, Math.min(_anchor, selection.anchor), _head);
273
+ view.dispatch(tr.setSelection(_newSelection));
274
+ return true;
275
+ }
276
+ }
277
+ }
278
+ }
279
+ return false;
280
+ }
281
+ },
237
282
  nodeViews: {
238
283
  // WARNING: referentiality-plugin also creates these nodeviews
239
284
  extension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
@@ -283,7 +283,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
283
283
  });
284
284
  _defineProperty(_assertThisInitialized(_this), "handleSelectedEmoji", function (emojiId) {
285
285
  _this.props.editorView.focus();
286
- insertEmoji(emojiId, INPUT_METHOD.PICKER)(_this.props.editorView.state, _this.props.editorView.dispatch);
286
+ insertEmoji(_this.editorAnalyticsAPI)(emojiId, INPUT_METHOD.PICKER)(_this.props.editorView.state, _this.props.editorView.dispatch);
287
287
  _this.toggleEmojiPicker();
288
288
  return true;
289
289
  });
@@ -1,36 +1,68 @@
1
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
+ */
2
14
  var isCollpasedExpand = function isCollpasedExpand(node) {
3
15
  return Boolean(node && ['expand', 'nestedExpand'].includes(node.type.name) && !node.attrs.__expanded);
4
16
  };
5
- var findFixedProblematicNodePosition = function findFixedProblematicNodePosition($pos, direction) {
6
- if ($pos.pos === 0 || $pos.depth === 0) {
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
+ var isProblematicNode = function isProblematicNode(node) {
25
+ return isCollpasedExpand(node) || isBodiedExtension(node);
26
+ };
27
+ var findFixedProblematicNodePosition = function findFixedProblematicNodePosition(doc, $head, direction) {
28
+ if ($head.pos === 0 || $head.depth === 0) {
7
29
  return null;
8
30
  }
9
- var pos = direction === 'up' ? $pos.before() : $pos.after();
10
- var $posResolved = $pos.doc.resolve(pos);
11
- var maybeExpandNode = direction === 'up' ? $posResolved.nodeBefore : $posResolved.nodeAfter;
12
- if (maybeExpandNode && isCollpasedExpand(maybeExpandNode)) {
13
- var nodeSize = maybeExpandNode.nodeSize;
14
- var expandPosition = direction === 'up' ? pos - nodeSize : pos + nodeSize;
15
- var startPosNode = Math.max(expandPosition, 0);
16
- var $startPosNode = $pos.doc.resolve(Math.min(startPosNode, $pos.doc.content.size));
17
- return $startPosNode;
31
+ if (direction === 'up') {
32
+ var pos = $head.before();
33
+ var $posResolved = $head.doc.resolve(pos);
34
+ var maybeProblematicNode = $posResolved.nodeBefore;
35
+ if (maybeProblematicNode && isProblematicNode(maybeProblematicNode)) {
36
+ var nodeSize = maybeProblematicNode.nodeSize;
37
+ var nodeStartPosition = pos - nodeSize;
38
+
39
+ // ($head.pos - 1) will correspond to (nodeStartPosition + nodeSize) when we are at the start of the text node
40
+ var isAtEndOfProblematicNode = $head.pos - 1 === nodeStartPosition + nodeSize;
41
+ if (isAtEndOfProblematicNode) {
42
+ var startPosNode = Math.max(nodeStartPosition, 0);
43
+ var $startPosNode = $head.doc.resolve(Math.min(startPosNode, $head.doc.content.size));
44
+ return $startPosNode;
45
+ }
46
+ }
47
+ }
48
+ if (direction === 'down') {
49
+ var _pos = $head.after();
50
+ var _maybeProblematicNode = doc.nodeAt(_pos);
51
+ if (_maybeProblematicNode && isProblematicNode(_maybeProblematicNode) && $head.pos + 1 === _pos) {
52
+ var _nodeSize = _maybeProblematicNode.nodeSize;
53
+ var nodePosition = _pos + _nodeSize;
54
+ var _startPosNode = Math.max(nodePosition, 0);
55
+ var _$startPosNode = $head.doc.resolve(Math.min(_startPosNode, $head.doc.content.size));
56
+ return _$startPosNode;
57
+ }
18
58
  }
19
59
  return null;
20
60
  };
21
61
  export var onKeydown = function onKeydown(view, event) {
22
62
  /*
23
- * This workaround is needed for some specific situation with collapsed expand.
24
- *
25
- * The way expand was built, no browser reconize selection on it.
26
- * For instance, when a selection going to a "collapsed" expand
27
- * the browser will try to send the cursor to inside the expand content (wrong),
28
- * this behavior is caused because the expand content is never true hidden
29
- * we just set the height to 1px.
30
- *
31
- * So, we need to capture a possible selection event
32
- * when a collapsed exxpand is the next node in the common depth.
33
- * If that is true, we create a new TextSelection and stop the event bubble
63
+ * This workaround is needed for some specific situations.
64
+ * - expand collapse
65
+ * - bodied extension
34
66
  */
35
67
  if (!(event instanceof KeyboardEvent)) {
36
68
  return false;
@@ -41,16 +73,21 @@ export var onKeydown = function onKeydown(view, event) {
41
73
  if (!['ArrowUp', 'ArrowDown', 'ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.key)) {
42
74
  return false;
43
75
  }
44
- var _view$state$selection = view.state.selection,
76
+ var _view$state = view.state,
77
+ doc = _view$state.doc,
78
+ _view$state$selection = _view$state.selection,
45
79
  $head = _view$state$selection.$head,
46
80
  $anchor = _view$state$selection.$anchor;
47
81
  if (event.key === 'ArrowRight' && $head.nodeAfter || event.key === 'ArrowLeft' && $head.nodeBefore) {
48
82
  return false;
49
83
  }
50
84
  var direction = ['ArrowLeft', 'ArrowUp', 'Home'].includes(event.key) ? 'up' : 'down';
51
- var $fixedProblematicNodePosition = findFixedProblematicNodePosition($head, direction);
85
+ var $fixedProblematicNodePosition = findFixedProblematicNodePosition(doc, $head, direction);
52
86
  if ($fixedProblematicNodePosition) {
53
- var forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, $fixedProblematicNodePosition.pos);
87
+ // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
88
+ var headOffset = event.key === 'ArrowLeft' ? -1 : 0;
89
+ var head = $fixedProblematicNodePosition.pos + headOffset;
90
+ var forcedTextSelection = TextSelection.create(view.state.doc, $anchor.pos, head);
54
91
  var tr = view.state.tr;
55
92
  tr.setSelection(forcedTextSelection);
56
93
  view.dispatch(tr);
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "187.9.0";
2
+ export var version = "187.9.2";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.9.0",
3
+ "version": "187.9.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,4 @@
1
1
  import type { EmojiId } from '@atlaskit/emoji';
2
2
  import type { Command } from '../../../types';
3
- import type { INPUT_METHOD } from '../../analytics';
4
- export declare function insertEmoji(emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD): Command;
3
+ import type { INPUT_METHOD, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
+ export declare const insertEmoji: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (emojiId: EmojiId, inputMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.ASCII | INPUT_METHOD.TYPEAHEAD) => Command;
@@ -3,7 +3,8 @@ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { FeatureFlags } from '../../../types/feature-flags';
6
- export declare function inputRulePlugin(schema: Schema, providerFactory: ProviderFactory, featureFlags: FeatureFlags): SafePlugin | undefined;
6
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
7
+ export declare function inputRulePlugin(schema: Schema, providerFactory: ProviderFactory, featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
7
8
  export declare const stateKey: PluginKey<any>;
8
- declare const plugins: (schema: Schema, providerFactory: ProviderFactory, featureFlags: FeatureFlags) => SafePlugin<any>[];
9
+ declare const plugins: (schema: Schema, providerFactory: ProviderFactory, featureFlags: FeatureFlags, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => SafePlugin<any>[];
9
10
  export default plugins;
@@ -5,13 +5,13 @@ import type { ExtensionHandlers, ExtensionProvider } from '@atlaskit/editor-comm
5
5
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
6
6
  import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
7
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
+ import type { ApplyChangeHandler } from '@atlaskit/editor-plugin-context-panel';
8
9
  import type { EditorAppearance } from '../../../types/editor-appearance';
9
10
  import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
10
11
  import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
11
12
  import { getPluginState, createCommand } from '../plugin-factory';
12
13
  import { pluginKey } from '../plugin-key';
13
14
  import type extensionPlugin from '../index';
14
- import type { ApplyChangeHandler } from '@atlaskit/editor-plugin-context-panel';
15
15
  export declare const createExtensionProviderHandler: (view: EditorView) => (name: string, provider?: Promise<ExtensionProvider>) => Promise<void>;
16
16
  export declare const createContextIdentifierProviderHandler: (view: EditorView) => (name: string, provider?: Promise<ContextIdentifierProvider>) => Promise<void>;
17
17
  export declare const handleUpdate: ({ view, prevState, domAtPos, extensionHandlers, applyChange, }: {
@@ -7,6 +7,7 @@ export declare class ToolbarInsertBlock extends React.PureComponent<Props & Wrap
7
7
  private dropdownButtonRef?;
8
8
  private emojiButtonRef?;
9
9
  private plusButtonRef?;
10
+ private editorAnalyticsAPI;
10
11
  state: State;
11
12
  static getDerivedStateFromProps(props: Props & WrappedComponentProps, state: State): State | null;
12
13
  componentDidUpdate(prevProps: Props): void;