@atlaskit/editor-plugin-extension 1.0.1 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-extension
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#72671](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72671) [`c446a8ca183b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c446a8ca183b) - ED-21912 Adding support for left arrow navigation from within MBE tabs.
8
+ - Updated dependencies
9
+
3
10
  ## 1.0.1
4
11
 
5
12
  ### Patch Changes
@@ -29,7 +29,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
29
29
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
30
30
  var _extensibility = require("@atlaskit/editor-common/extensibility");
31
31
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
32
- var _selection = require("@atlaskit/editor-common/selection");
32
+ var _selection2 = require("@atlaskit/editor-common/selection");
33
33
  var _state = require("@atlaskit/editor-prosemirror/state");
34
34
  var _utils = require("@atlaskit/editor-prosemirror/utils");
35
35
  var _commands = require("../commands");
@@ -238,7 +238,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, provid
238
238
  var maybeBodiedExtension = selection instanceof _state.TextSelection ? (0, _utils.findParentNodeOfTypeClosestToPos)($head, bodiedExtension) : (0, _utils.findSelectedNodeOfType)(bodiedExtension)(selection);
239
239
  if (maybeBodiedExtension) {
240
240
  var end = maybeBodiedExtension.pos + maybeBodiedExtension.node.nodeSize;
241
- if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' && (0, _selection.isSelectionAtStartOfNode)($head, maybeBodiedExtension)) {
241
+ if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' && (0, _selection2.isSelectionAtStartOfNode)($head, maybeBodiedExtension)) {
242
242
  var anchor = end + 1;
243
243
 
244
244
  // an offset is used here so that left arrow selects the first character before the node (consistent with arrow right)
@@ -248,7 +248,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, provid
248
248
  view.dispatch(tr.setSelection(newSelection));
249
249
  return true;
250
250
  }
251
- if (event.key === 'ArrowDown' || event.key === 'ArrowRight' && (0, _selection.isSelectionAtEndOfNode)($head, maybeBodiedExtension)) {
251
+ if (event.key === 'ArrowDown' || event.key === 'ArrowRight' && (0, _selection2.isSelectionAtEndOfNode)($head, maybeBodiedExtension)) {
252
252
  var _anchor = maybeBodiedExtension.pos - 1;
253
253
  var _head = end + 1;
254
254
  var _newSelection = _state.TextSelection.create(doc, Math.min(_anchor, selection.anchor), _head);
@@ -258,6 +258,34 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, provid
258
258
  }
259
259
  }
260
260
  }
261
+
262
+ // Handle non shift key case for MBE
263
+ if (event instanceof KeyboardEvent && !event.shiftKey && event.key === 'ArrowLeft') {
264
+ var _view$state2 = view.state,
265
+ _schema = _view$state2.schema,
266
+ _selection = _view$state2.selection,
267
+ _$head = _view$state2.selection.$head,
268
+ _doc = _view$state2.doc,
269
+ _tr = _view$state2.tr;
270
+ var _schema$nodes = _schema.nodes,
271
+ multiBodiedExtension = _schema$nodes.multiBodiedExtension,
272
+ extensionFrame = _schema$nodes.extensionFrame,
273
+ paragraph = _schema$nodes.paragraph;
274
+ if (_selection instanceof _selection2.GapCursorSelection || _selection instanceof _state.TextSelection && _$head.parent.type === paragraph) {
275
+ var maybeMultiBodiedExtension = (0, _utils.findParentNodeOfTypeClosestToPos)(_$head, multiBodiedExtension);
276
+ if (maybeMultiBodiedExtension) {
277
+ var _tr$doc$nodeAt;
278
+ /* In case of gap cursor, we need to decrement the position by 1 as we need to check the node at previous position
279
+ * In case of text selection, we need to decrement the position by 2 as we need to jump back twice, once from text node and then its parent paragraph node
280
+ */
281
+ var previousPositionDecrement = _selection instanceof _selection2.GapCursorSelection ? 1 : 2;
282
+ if (((_tr$doc$nodeAt = _tr.doc.nodeAt(_$head.pos - previousPositionDecrement)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.type) === extensionFrame) {
283
+ var _newSelection2 = _state.TextSelection.create(_doc, _tr.doc.resolve(_$head.pos - previousPositionDecrement).start(_$head.depth - previousPositionDecrement));
284
+ view.dispatch(_tr.setSelection(_newSelection2));
285
+ }
286
+ }
287
+ }
288
+ }
261
289
  return false;
262
290
  }
263
291
  },
@@ -270,7 +298,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, provid
270
298
  inlineExtension: (0, _extensibility.ExtensionNodeView)(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi),
271
299
  multiBodiedExtension: (0, _extensibility.ExtensionNodeView)(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions, pluginInjectionApi)
272
300
  },
273
- handleClickOn: (0, _selection.createSelectionClickHandler)(['extension', 'bodiedExtension', 'multiBodiedExtension'], function (target) {
301
+ handleClickOn: (0, _selection2.createSelectionClickHandler)(['extension', 'bodiedExtension', 'multiBodiedExtension'], function (target) {
274
302
  return !target.closest('.extension-content');
275
303
  }, {
276
304
  useLongPressSelection: useLongPressSelection
@@ -1,6 +1,6 @@
1
1
  import { ExtensionNodeView } from '@atlaskit/editor-common/extensibility';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { createSelectionClickHandler, isSelectionAtEndOfNode, isSelectionAtStartOfNode } from '@atlaskit/editor-common/selection';
3
+ import { createSelectionClickHandler, GapCursorSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode } from '@atlaskit/editor-common/selection';
4
4
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
5
  import { findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { clearEditingContext, updateState } from '../commands';
@@ -190,6 +190,38 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
190
190
  }
191
191
  }
192
192
  }
193
+
194
+ // Handle non shift key case for MBE
195
+ if (event instanceof KeyboardEvent && !event.shiftKey && event.key === 'ArrowLeft') {
196
+ const {
197
+ schema,
198
+ selection,
199
+ selection: {
200
+ $head
201
+ },
202
+ doc,
203
+ tr
204
+ } = view.state;
205
+ const {
206
+ multiBodiedExtension,
207
+ extensionFrame,
208
+ paragraph
209
+ } = schema.nodes;
210
+ if (selection instanceof GapCursorSelection || selection instanceof TextSelection && $head.parent.type === paragraph) {
211
+ const maybeMultiBodiedExtension = findParentNodeOfTypeClosestToPos($head, multiBodiedExtension);
212
+ if (maybeMultiBodiedExtension) {
213
+ var _tr$doc$nodeAt;
214
+ /* In case of gap cursor, we need to decrement the position by 1 as we need to check the node at previous position
215
+ * In case of text selection, we need to decrement the position by 2 as we need to jump back twice, once from text node and then its parent paragraph node
216
+ */
217
+ const previousPositionDecrement = selection instanceof GapCursorSelection ? 1 : 2;
218
+ if (((_tr$doc$nodeAt = tr.doc.nodeAt($head.pos - previousPositionDecrement)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.type) === extensionFrame) {
219
+ const newSelection = TextSelection.create(doc, tr.doc.resolve($head.pos - previousPositionDecrement).start($head.depth - previousPositionDecrement));
220
+ view.dispatch(tr.setSelection(newSelection));
221
+ }
222
+ }
223
+ }
224
+ }
193
225
  return false;
194
226
  }
195
227
  },
@@ -3,7 +3,7 @@ import _typeof from "@babel/runtime/helpers/typeof";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { ExtensionNodeView } from '@atlaskit/editor-common/extensibility';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { createSelectionClickHandler, isSelectionAtEndOfNode, isSelectionAtStartOfNode } from '@atlaskit/editor-common/selection';
6
+ import { createSelectionClickHandler, GapCursorSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode } from '@atlaskit/editor-common/selection';
7
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
9
9
  import { clearEditingContext, updateState } from '../commands';
@@ -232,6 +232,34 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
232
232
  }
233
233
  }
234
234
  }
235
+
236
+ // Handle non shift key case for MBE
237
+ if (event instanceof KeyboardEvent && !event.shiftKey && event.key === 'ArrowLeft') {
238
+ var _view$state2 = view.state,
239
+ _schema = _view$state2.schema,
240
+ _selection = _view$state2.selection,
241
+ _$head = _view$state2.selection.$head,
242
+ _doc = _view$state2.doc,
243
+ _tr = _view$state2.tr;
244
+ var _schema$nodes = _schema.nodes,
245
+ multiBodiedExtension = _schema$nodes.multiBodiedExtension,
246
+ extensionFrame = _schema$nodes.extensionFrame,
247
+ paragraph = _schema$nodes.paragraph;
248
+ if (_selection instanceof GapCursorSelection || _selection instanceof TextSelection && _$head.parent.type === paragraph) {
249
+ var maybeMultiBodiedExtension = findParentNodeOfTypeClosestToPos(_$head, multiBodiedExtension);
250
+ if (maybeMultiBodiedExtension) {
251
+ var _tr$doc$nodeAt;
252
+ /* In case of gap cursor, we need to decrement the position by 1 as we need to check the node at previous position
253
+ * In case of text selection, we need to decrement the position by 2 as we need to jump back twice, once from text node and then its parent paragraph node
254
+ */
255
+ var previousPositionDecrement = _selection instanceof GapCursorSelection ? 1 : 2;
256
+ if (((_tr$doc$nodeAt = _tr.doc.nodeAt(_$head.pos - previousPositionDecrement)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.type) === extensionFrame) {
257
+ var _newSelection2 = TextSelection.create(_doc, _tr.doc.resolve(_$head.pos - previousPositionDecrement).start(_$head.depth - previousPositionDecrement));
258
+ view.dispatch(_tr.setSelection(_newSelection2));
259
+ }
260
+ }
261
+ }
262
+ }
235
263
  return false;
236
264
  }
237
265
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-extension",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "editor-plugin-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/button": "^17.4.0",
32
32
  "@atlaskit/checkbox": "^13.0.0",
33
33
  "@atlaskit/datetime-picker": "^13.0.3",
34
- "@atlaskit/editor-common": "^78.0.0",
34
+ "@atlaskit/editor-common": "^78.1.0",
35
35
  "@atlaskit/editor-json-transformer": "^8.10.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
37
37
  "@atlaskit/editor-plugin-context-identifier": "^1.0.0",