@atlaskit/editor-plugin-block-controls 7.11.2 → 7.11.3

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,18 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 7.11.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`59c74907ab1c6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/59c74907ab1c6) -
8
+ [ux] EDITOR-3727 fix selection preservation on empty lines
9
+ - [`7e5df3d5beaf3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e5df3d5beaf3) -
10
+ Add new flattenListStep and unwrapListStep and use for list -> paragraph step. Also moved
11
+ expandToBlockRange util function to editor-common to re-use
12
+ - [`e3779b75fdeca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e3779b75fdeca) -
13
+ EDITOR-1643 Promote syncBlock and bodiedSyncBlock to full schema
14
+ - Updated dependencies
15
+
3
16
  ## 7.11.2
4
17
 
5
18
  ### Patch Changes
@@ -8,6 +8,7 @@ exports.createSelectionPreservationPlugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _monitoring = require("@atlaskit/editor-common/monitoring");
10
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _selection = require("@atlaskit/editor-common/selection");
11
12
  var _state = require("@atlaskit/editor-prosemirror/state");
12
13
  var _transform = require("@atlaskit/editor-prosemirror/transform");
13
14
  var _main = require("../main");
@@ -81,10 +82,9 @@ var createSelectionPreservationPlugin = exports.createSelectionPreservationPlugi
81
82
  });
82
83
  }
83
84
  var currSel = newState.selection;
84
- var wasEmptySelection = savedSel.from === savedSel.to;
85
85
  var selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
86
86
  var selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
87
- if (wasEmptySelection || selectionUnchanged || selectionInvalid) {
87
+ if (selectionUnchanged || selectionInvalid) {
88
88
  return null;
89
89
  }
90
90
  try {
@@ -106,18 +106,27 @@ var mapSelection = function mapSelection(selection, tr) {
106
106
  if (selection instanceof _state.TextSelection) {
107
107
  var from = mapping.map(selection.from);
108
108
  var to = mapping.map(selection.to);
109
+ var isSelectionEmpty = from === to;
110
+ var wasSelectionEmpty = selection.from === selection.to;
111
+ if (isSelectionEmpty) {
112
+ if (!wasSelectionEmpty) {
113
+ // If selection has become empty i.e. content has been deleted, stop preserving
114
+ return undefined;
115
+ }
116
+ // When preserving a cursor selection, just map the position without expanding
117
+ return new _state.TextSelection(tr.doc.resolve(from));
118
+ }
109
119
 
110
120
  // expand the text selection range to block boundaries, so as document changes occur the
111
121
  // selection always includes whole nodes
112
- var expanded = (0, _getSelection.expandToBlockRange)(tr.doc.resolve(from), tr.doc.resolve(to));
122
+ var expanded = (0, _selection.expandToBlockRange)(tr.doc.resolve(from), tr.doc.resolve(to));
113
123
 
114
124
  // collapse the expanded range to a valid selection range
115
125
  var _collapseToSelectionR = (0, _getSelection.collapseToSelectionRange)(expanded.$from, expanded.$to),
116
126
  $from = _collapseToSelectionR.$from,
117
127
  $to = _collapseToSelectionR.$to;
118
128
 
119
- // stop preserving if preserved selection becomes invalid or collapsed to a cursor
120
- // e.g. after deleting the selection
129
+ // stop preserving if preserved selection becomes invalid
121
130
  if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
122
131
  return undefined;
123
132
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isNodeWithCodeBlock = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = exports.expandToBlockRange = exports.collapseToSelectionRange = void 0;
6
+ exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isNodeWithCodeBlock = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = exports.collapseToSelectionRange = void 0;
7
7
  var _selection2 = require("@atlaskit/editor-common/selection");
8
8
  var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
9
9
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -222,28 +222,6 @@ var rootTaskListDepth = exports.rootTaskListDepth = function rootTaskListDepth(t
222
222
  return depth;
223
223
  };
224
224
 
225
- /**
226
- * This expands the given $from and $to resolved positions to the block boundaries
227
- * spanning all nodes in the range up to the nearest common ancestor.
228
- *
229
- * @param $from The resolved start position
230
- * @param $to The resolved end position
231
- * @returns An object containing the expanded $from and $to resolved positions
232
- */
233
- var expandToBlockRange = exports.expandToBlockRange = function expandToBlockRange($from, $to) {
234
- var range = $from.blockRange($to);
235
- if (!range) {
236
- return {
237
- $from: $from,
238
- $to: $to
239
- };
240
- }
241
- return {
242
- $from: $from.doc.resolve(range.start),
243
- $to: $to.doc.resolve(range.end)
244
- };
245
- };
246
-
247
225
  /**
248
226
  * Collapses the given $from and $to resolved positions to the nearest valid selection range.
249
227
  *
@@ -254,14 +232,14 @@ var expandToBlockRange = exports.expandToBlockRange = function expandToBlockRang
254
232
  * @returns An object containing the collapsed $from and $to resolved positions
255
233
  */
256
234
  var collapseToSelectionRange = exports.collapseToSelectionRange = function collapseToSelectionRange($from, $to) {
257
- var resolvedRangeEnd = $from.doc.resolve($to.pos);
258
-
235
+ var _$to$nodeBefore$nodeS, _$to$nodeBefore;
259
236
  // Get the selections that would be made for the first and last node in the range
260
237
  // We re-use the getSelection logic as it already handles various node types and edge cases
261
- var firstNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, $from.pos);
262
- var lastNodeSize = resolvedRangeEnd.nodeBefore ? resolvedRangeEnd.nodeBefore.nodeSize : 0;
263
- var lastNodeStartPos = resolvedRangeEnd.pos - lastNodeSize;
264
- var lastNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, lastNodeStartPos);
238
+ // always pass true for selectionEmpty to emulate a cursor selection within the node
239
+ var firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
240
+ var lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
241
+ var lastNodeStartPos = $to.pos - lastNodeSize;
242
+ var lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
265
243
 
266
244
  // Return a selection spanning from the start of the first node selection to the end of the last node selection
267
245
  return {
@@ -1,9 +1,10 @@
1
1
  import { logException } from '@atlaskit/editor-common/monitoring';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { expandToBlockRange } from '@atlaskit/editor-common/selection';
3
4
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
5
  import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
5
6
  import { getBlockControlsMeta } from '../main';
6
- import { collapseToSelectionRange, expandToBlockRange } from '../utils/getSelection';
7
+ import { collapseToSelectionRange } from '../utils/getSelection';
7
8
  import { stopPreservingSelection } from './editor-commands';
8
9
  import { selectionPreservationPluginKey } from './plugin-key';
9
10
  import { getSelectionPreservationMeta, hasUserSelectionChange } from './utils';
@@ -74,10 +75,9 @@ export const createSelectionPreservationPlugin = () => {
74
75
  });
75
76
  }
76
77
  const currSel = newState.selection;
77
- const wasEmptySelection = savedSel.from === savedSel.to;
78
78
  const selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
79
79
  const selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
80
- if (wasEmptySelection || selectionUnchanged || selectionInvalid) {
80
+ if (selectionUnchanged || selectionInvalid) {
81
81
  return null;
82
82
  }
83
83
  try {
@@ -100,6 +100,16 @@ const mapSelection = (selection, tr) => {
100
100
  if (selection instanceof TextSelection) {
101
101
  const from = mapping.map(selection.from);
102
102
  const to = mapping.map(selection.to);
103
+ const isSelectionEmpty = from === to;
104
+ const wasSelectionEmpty = selection.from === selection.to;
105
+ if (isSelectionEmpty) {
106
+ if (!wasSelectionEmpty) {
107
+ // If selection has become empty i.e. content has been deleted, stop preserving
108
+ return undefined;
109
+ }
110
+ // When preserving a cursor selection, just map the position without expanding
111
+ return new TextSelection(tr.doc.resolve(from));
112
+ }
103
113
 
104
114
  // expand the text selection range to block boundaries, so as document changes occur the
105
115
  // selection always includes whole nodes
@@ -111,8 +121,7 @@ const mapSelection = (selection, tr) => {
111
121
  $to
112
122
  } = collapseToSelectionRange(expanded.$from, expanded.$to);
113
123
 
114
- // stop preserving if preserved selection becomes invalid or collapsed to a cursor
115
- // e.g. after deleting the selection
124
+ // stop preserving if preserved selection becomes invalid
116
125
  if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
117
126
  return undefined;
118
127
  }
@@ -219,28 +219,6 @@ export const rootTaskListDepth = taskListPos => {
219
219
  return depth;
220
220
  };
221
221
 
222
- /**
223
- * This expands the given $from and $to resolved positions to the block boundaries
224
- * spanning all nodes in the range up to the nearest common ancestor.
225
- *
226
- * @param $from The resolved start position
227
- * @param $to The resolved end position
228
- * @returns An object containing the expanded $from and $to resolved positions
229
- */
230
- export const expandToBlockRange = ($from, $to) => {
231
- const range = $from.blockRange($to);
232
- if (!range) {
233
- return {
234
- $from,
235
- $to
236
- };
237
- }
238
- return {
239
- $from: $from.doc.resolve(range.start),
240
- $to: $to.doc.resolve(range.end)
241
- };
242
- };
243
-
244
222
  /**
245
223
  * Collapses the given $from and $to resolved positions to the nearest valid selection range.
246
224
  *
@@ -251,14 +229,14 @@ export const expandToBlockRange = ($from, $to) => {
251
229
  * @returns An object containing the collapsed $from and $to resolved positions
252
230
  */
253
231
  export const collapseToSelectionRange = ($from, $to) => {
254
- const resolvedRangeEnd = $from.doc.resolve($to.pos);
255
-
232
+ var _$to$nodeBefore$nodeS, _$to$nodeBefore;
256
233
  // Get the selections that would be made for the first and last node in the range
257
234
  // We re-use the getSelection logic as it already handles various node types and edge cases
258
- const firstNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, $from.pos);
259
- const lastNodeSize = resolvedRangeEnd.nodeBefore ? resolvedRangeEnd.nodeBefore.nodeSize : 0;
260
- const lastNodeStartPos = resolvedRangeEnd.pos - lastNodeSize;
261
- const lastNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, lastNodeStartPos);
235
+ // always pass true for selectionEmpty to emulate a cursor selection within the node
236
+ const firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
237
+ const lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
238
+ const lastNodeStartPos = $to.pos - lastNodeSize;
239
+ const lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
262
240
 
263
241
  // Return a selection spanning from the start of the first node selection to the end of the last node selection
264
242
  return {
@@ -3,10 +3,11 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
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
4
  import { logException } from '@atlaskit/editor-common/monitoring';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { expandToBlockRange } from '@atlaskit/editor-common/selection';
6
7
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
7
8
  import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
8
9
  import { getBlockControlsMeta } from '../main';
9
- import { collapseToSelectionRange, expandToBlockRange } from '../utils/getSelection';
10
+ import { collapseToSelectionRange } from '../utils/getSelection';
10
11
  import { stopPreservingSelection } from './editor-commands';
11
12
  import { selectionPreservationPluginKey } from './plugin-key';
12
13
  import { getSelectionPreservationMeta, hasUserSelectionChange } from './utils';
@@ -75,10 +76,9 @@ export var createSelectionPreservationPlugin = function createSelectionPreservat
75
76
  });
76
77
  }
77
78
  var currSel = newState.selection;
78
- var wasEmptySelection = savedSel.from === savedSel.to;
79
79
  var selectionUnchanged = currSel.from === savedSel.from && currSel.to === savedSel.to;
80
80
  var selectionInvalid = savedSel.from < 0 || savedSel.to > newState.doc.content.size;
81
- if (wasEmptySelection || selectionUnchanged || selectionInvalid) {
81
+ if (selectionUnchanged || selectionInvalid) {
82
82
  return null;
83
83
  }
84
84
  try {
@@ -100,6 +100,16 @@ var mapSelection = function mapSelection(selection, tr) {
100
100
  if (selection instanceof TextSelection) {
101
101
  var from = mapping.map(selection.from);
102
102
  var to = mapping.map(selection.to);
103
+ var isSelectionEmpty = from === to;
104
+ var wasSelectionEmpty = selection.from === selection.to;
105
+ if (isSelectionEmpty) {
106
+ if (!wasSelectionEmpty) {
107
+ // If selection has become empty i.e. content has been deleted, stop preserving
108
+ return undefined;
109
+ }
110
+ // When preserving a cursor selection, just map the position without expanding
111
+ return new TextSelection(tr.doc.resolve(from));
112
+ }
103
113
 
104
114
  // expand the text selection range to block boundaries, so as document changes occur the
105
115
  // selection always includes whole nodes
@@ -110,8 +120,7 @@ var mapSelection = function mapSelection(selection, tr) {
110
120
  $from = _collapseToSelectionR.$from,
111
121
  $to = _collapseToSelectionR.$to;
112
122
 
113
- // stop preserving if preserved selection becomes invalid or collapsed to a cursor
114
- // e.g. after deleting the selection
123
+ // stop preserving if preserved selection becomes invalid
115
124
  if ($from.pos < 0 || $to.pos > tr.doc.content.size || $from.pos >= $to.pos) {
116
125
  return undefined;
117
126
  }
@@ -216,28 +216,6 @@ export var rootTaskListDepth = function rootTaskListDepth(taskListPos) {
216
216
  return depth;
217
217
  };
218
218
 
219
- /**
220
- * This expands the given $from and $to resolved positions to the block boundaries
221
- * spanning all nodes in the range up to the nearest common ancestor.
222
- *
223
- * @param $from The resolved start position
224
- * @param $to The resolved end position
225
- * @returns An object containing the expanded $from and $to resolved positions
226
- */
227
- export var expandToBlockRange = function expandToBlockRange($from, $to) {
228
- var range = $from.blockRange($to);
229
- if (!range) {
230
- return {
231
- $from: $from,
232
- $to: $to
233
- };
234
- }
235
- return {
236
- $from: $from.doc.resolve(range.start),
237
- $to: $to.doc.resolve(range.end)
238
- };
239
- };
240
-
241
219
  /**
242
220
  * Collapses the given $from and $to resolved positions to the nearest valid selection range.
243
221
  *
@@ -248,14 +226,14 @@ export var expandToBlockRange = function expandToBlockRange($from, $to) {
248
226
  * @returns An object containing the collapsed $from and $to resolved positions
249
227
  */
250
228
  export var collapseToSelectionRange = function collapseToSelectionRange($from, $to) {
251
- var resolvedRangeEnd = $from.doc.resolve($to.pos);
252
-
229
+ var _$to$nodeBefore$nodeS, _$to$nodeBefore;
253
230
  // Get the selections that would be made for the first and last node in the range
254
231
  // We re-use the getSelection logic as it already handles various node types and edge cases
255
- var firstNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, $from.pos);
256
- var lastNodeSize = resolvedRangeEnd.nodeBefore ? resolvedRangeEnd.nodeBefore.nodeSize : 0;
257
- var lastNodeStartPos = resolvedRangeEnd.pos - lastNodeSize;
258
- var lastNodeSelection = newGetSelection($from.doc, $from.pos === $to.pos, lastNodeStartPos);
232
+ // always pass true for selectionEmpty to emulate a cursor selection within the node
233
+ var firstNodeSelection = newGetSelection($from.doc, true, $from.pos);
234
+ var lastNodeSize = (_$to$nodeBefore$nodeS = (_$to$nodeBefore = $to.nodeBefore) === null || _$to$nodeBefore === void 0 ? void 0 : _$to$nodeBefore.nodeSize) !== null && _$to$nodeBefore$nodeS !== void 0 ? _$to$nodeBefore$nodeS : 0;
235
+ var lastNodeStartPos = $to.pos - lastNodeSize;
236
+ var lastNodeSelection = newGetSelection($from.doc, true, lastNodeStartPos);
259
237
 
260
238
  // Return a selection spanning from the start of the first node selection to the end of the last node selection
261
239
  return {
@@ -20,18 +20,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
20
20
  export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
21
21
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
22
22
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
23
- /**
24
- * This expands the given $from and $to resolved positions to the block boundaries
25
- * spanning all nodes in the range up to the nearest common ancestor.
26
- *
27
- * @param $from The resolved start position
28
- * @param $to The resolved end position
29
- * @returns An object containing the expanded $from and $to resolved positions
30
- */
31
- export declare const expandToBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => {
32
- $from: ResolvedPos;
33
- $to: ResolvedPos;
34
- };
35
23
  /**
36
24
  * Collapses the given $from and $to resolved positions to the nearest valid selection range.
37
25
  *
@@ -20,18 +20,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
20
20
  export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
21
21
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
22
22
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
23
- /**
24
- * This expands the given $from and $to resolved positions to the block boundaries
25
- * spanning all nodes in the range up to the nearest common ancestor.
26
- *
27
- * @param $from The resolved start position
28
- * @param $to The resolved end position
29
- * @returns An object containing the expanded $from and $to resolved positions
30
- */
31
- export declare const expandToBlockRange: ($from: ResolvedPos, $to: ResolvedPos) => {
32
- $from: ResolvedPos;
33
- $to: ResolvedPos;
34
- };
35
23
  /**
36
24
  * Collapses the given $from and $to resolved positions to the nearest valid selection range.
37
25
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "7.11.2",
3
+ "version": "7.11.3",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "atlaskit:src": "src/index.ts",
30
30
  "dependencies": {
31
- "@atlaskit/adf-schema": "^51.4.0",
31
+ "@atlaskit/adf-schema": "^51.5.1",
32
32
  "@atlaskit/browser-apis": "^0.0.1",
33
33
  "@atlaskit/editor-plugin-accessibility-utils": "^6.0.0",
34
34
  "@atlaskit/editor-plugin-analytics": "^6.2.0",
@@ -54,7 +54,7 @@
54
54
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
55
55
  "@atlaskit/primitives": "^16.4.0",
56
56
  "@atlaskit/theme": "^21.0.0",
57
- "@atlaskit/tmp-editor-statsig": "^14.4.0",
57
+ "@atlaskit/tmp-editor-statsig": "^14.5.0",
58
58
  "@atlaskit/tokens": "^8.4.0",
59
59
  "@atlaskit/tooltip": "^20.10.0",
60
60
  "@babel/runtime": "^7.0.0",
@@ -66,7 +66,7 @@
66
66
  "uuid": "^3.1.0"
67
67
  },
68
68
  "peerDependencies": {
69
- "@atlaskit/editor-common": "^110.37.0",
69
+ "@atlaskit/editor-common": "^110.38.0",
70
70
  "react": "^18.2.0",
71
71
  "react-dom": "^18.2.0",
72
72
  "react-intl-next": "npm:react-intl@^5.18.1"