@atlaskit/editor-plugin-block-controls 7.12.0 → 7.13.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 7.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`b3a509f727a0f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b3a509f727a0f) -
8
+ ED-29696 update CSS anchor selector to enable less anchors
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 7.12.1
15
+
16
+ ### Patch Changes
17
+
18
+ - [`79cafe9f09a05`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/79cafe9f09a05) -
19
+ EDITOR-3756 More general approach to support custom preserved selection mapping
20
+
3
21
  ## 7.12.0
4
22
 
5
23
  ### Minor Changes
@@ -15,6 +15,7 @@ var _types = require("@atlaskit/editor-common/types");
15
15
  var _utils = require("@atlaskit/editor-common/utils");
16
16
  var _model = require("@atlaskit/editor-prosemirror/model");
17
17
  var _state = require("@atlaskit/editor-prosemirror/state");
18
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
18
19
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
19
20
  var _utils3 = require("@atlaskit/editor-tables/utils");
20
21
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
@@ -426,7 +427,11 @@ var moveNode = exports.moveNode = function moveNode(api) {
426
427
  if (inputMethod === _analytics.INPUT_METHOD.DRAG_AND_DROP) {
427
428
  tr = (0, _getSelection.setCursorPositionAtMovedNode)(tr, mappedTo, api);
428
429
  } else if (preservedSelection) {
429
- // do nothing here to allow the selection preservation plugin to handle mapping the selection
430
+ var _currMeta = tr.getMeta(_main.key);
431
+ var nodeMovedOffset = mappedTo - sliceFrom;
432
+ tr.setMeta(_main.key, _objectSpread(_objectSpread({}, _currMeta), {}, {
433
+ preservedSelectionMapping: new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])])
434
+ }));
430
435
  } else if (isMultiSelect) {
431
436
  var _api$blockControls$co;
432
437
  tr = (_api$blockControls$co = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
@@ -437,8 +442,7 @@ var moveNode = exports.moveNode = function moveNode(api) {
437
442
  }
438
443
  var currMeta = tr.getMeta(_main.key);
439
444
  tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
440
- nodeMoved: true,
441
- nodeMovedOffset: mappedTo - sliceFrom
445
+ nodeMoved: true
442
446
  }));
443
447
  api === null || api === void 0 || api.core.actions.focus();
444
448
  var $mappedTo = tr.doc.resolve(mappedTo);
@@ -32,7 +32,7 @@ var getNodeSelector = function getNodeSelector(ignoreNodes, ignoreNodeDescendant
32
32
  var ignoreNodeDescendantsSelectorList = ignoreNodeDescendants.map(function (node) {
33
33
  if (node === 'table') {
34
34
  // Special case for table to exclude its direct descendants
35
- return ["[data-prosemirror-node-name=\"tableCell\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > [data-node-anchor]"];
35
+ return ["[data-prosemirror-node-name=\"tableCell\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableCell\"] > *:not([data-node-anchor]) > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > *:not([data-node-anchor]) > [data-node-anchor]"];
36
36
  }
37
37
  return "[data-prosemirror-node-name=\"".concat(node, "\"] [data-node-anchor]");
38
38
  });
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.mapPreservedSelection = exports.getSelectedSlicePosition = exports.getMultiSelectionIfPosInside = exports.expandSelectionHeadToNodeAtPos = exports.alignAnchorHeadInDirectionOfPos = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _transform = require("@atlaskit/editor-prosemirror/transform");
10
9
  var _main = require("../main");
11
10
  var _getSelection = require("./getSelection");
12
11
  var getMultiSelectionIfPosInside = exports.getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
@@ -91,9 +90,8 @@ var alignAnchorHeadInDirectionOfPos = exports.alignAnchorHeadInDirectionOfPos =
91
90
  */
92
91
  var mapPreservedSelection = exports.mapPreservedSelection = function mapPreservedSelection(selection, tr) {
93
92
  var _ref = (0, _main.getBlockControlsMeta)(tr) || {},
94
- nodeMoved = _ref.nodeMoved,
95
- nodeMovedOffset = _ref.nodeMovedOffset;
96
- var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new _transform.Mapping([new _transform.StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
93
+ preservedSelectionMapping = _ref.preservedSelectionMapping;
94
+ var mapping = preservedSelectionMapping || tr.mapping;
97
95
  if (selection instanceof _state.TextSelection) {
98
96
  var from = mapping.map(selection.from);
99
97
  var to = mapping.map(selection.to);
@@ -407,11 +407,11 @@ var blockCardWithoutLayout = (0, _react.css)({
407
407
  });
408
408
  var nextAnchorSelector = ['&[data-node-anchor]',
409
409
  // adjacent sibling with anchor
410
- '&:not([data-node-anchor]) [data-node-anchor]',
411
- // nested anchor inside adjacent sibling
410
+ '&:not([data-node-anchor]) [data-node-anchor]:first-of-type',
411
+ // first nested anchor inside adjacent sibling
412
412
  '&.ProseMirror-widget + [data-node-anchor]',
413
413
  // adjacent sibling with anchor (when next to a widget like gap cursor)
414
- '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]' // nested anchor inside adjacent sibling (when next to a widget like gap cursor)
414
+ '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]:first-of-type' // first nested anchor inside adjacent sibling (when next to a widget like gap cursor)
415
415
  ].join(', ');
416
416
  var dragHandlerAnchorStyles = (0, _react.css)({
417
417
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
@@ -7,6 +7,7 @@ import { DIRECTION } from '@atlaskit/editor-common/types';
7
7
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
8
8
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
9
9
  import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
10
+ import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
10
11
  import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
11
12
  import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
12
13
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -426,7 +427,12 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
426
427
  if (inputMethod === INPUT_METHOD.DRAG_AND_DROP) {
427
428
  tr = setCursorPositionAtMovedNode(tr, mappedTo, api);
428
429
  } else if (preservedSelection) {
429
- // do nothing here to allow the selection preservation plugin to handle mapping the selection
430
+ const currMeta = tr.getMeta(key);
431
+ const nodeMovedOffset = mappedTo - sliceFrom;
432
+ tr.setMeta(key, {
433
+ ...currMeta,
434
+ preservedSelectionMapping: new Mapping([new StepMap([0, 0, nodeMovedOffset])])
435
+ });
430
436
  } else if (isMultiSelect) {
431
437
  var _api$blockControls$co2;
432
438
  tr = (_api$blockControls$co2 = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
@@ -438,8 +444,7 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
438
444
  const currMeta = tr.getMeta(key);
439
445
  tr.setMeta(key, {
440
446
  ...currMeta,
441
- nodeMoved: true,
442
- nodeMovedOffset: mappedTo - sliceFrom
447
+ nodeMoved: true
443
448
  });
444
449
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
445
450
  const $mappedTo = tr.doc.resolve(mappedTo);
@@ -22,7 +22,7 @@ const getNodeSelector = (ignoreNodes, ignoreNodeDescendants) => {
22
22
  const ignoreNodeDescendantsSelectorList = ignoreNodeDescendants.map(node => {
23
23
  if (node === 'table') {
24
24
  // Special case for table to exclude its direct descendants
25
- return [`[data-prosemirror-node-name="tableCell"] > [data-node-anchor]`, `[data-prosemirror-node-name="tableHeader"] > [data-node-anchor]`];
25
+ return [`[data-prosemirror-node-name="tableCell"] > [data-node-anchor]`, `[data-prosemirror-node-name="tableCell"] > *:not([data-node-anchor]) > [data-node-anchor]`, `[data-prosemirror-node-name="tableHeader"] > [data-node-anchor]`, `[data-prosemirror-node-name="tableHeader"] > *:not([data-node-anchor]) > [data-node-anchor]`];
26
26
  }
27
27
  return `[data-prosemirror-node-name="${node}"] [data-node-anchor]`;
28
28
  });
@@ -1,6 +1,5 @@
1
1
  import { expandToBlockRange } from '@atlaskit/editor-common/selection';
2
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
4
3
  import { getBlockControlsMeta, key } from '../main';
5
4
  import { collapseToSelectionRange } from './getSelection';
6
5
  export const getMultiSelectionIfPosInside = (api, pos, tr) => {
@@ -86,10 +85,9 @@ export const alignAnchorHeadInDirectionOfPos = (selection, pos) => {
86
85
  */
87
86
  export const mapPreservedSelection = (selection, tr) => {
88
87
  const {
89
- nodeMoved,
90
- nodeMovedOffset
88
+ preservedSelectionMapping
91
89
  } = getBlockControlsMeta(tr) || {};
92
- const mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
90
+ const mapping = preservedSelectionMapping || tr.mapping;
93
91
  if (selection instanceof TextSelection) {
94
92
  const from = mapping.map(selection.from);
95
93
  const to = mapping.map(selection.to);
@@ -485,11 +485,11 @@ const blockCardWithoutLayout = css({
485
485
  });
486
486
  const nextAnchorSelector = ['&[data-node-anchor]',
487
487
  // adjacent sibling with anchor
488
- '&:not([data-node-anchor]) [data-node-anchor]',
489
- // nested anchor inside adjacent sibling
488
+ '&:not([data-node-anchor]) [data-node-anchor]:first-of-type',
489
+ // first nested anchor inside adjacent sibling
490
490
  '&.ProseMirror-widget + [data-node-anchor]',
491
491
  // adjacent sibling with anchor (when next to a widget like gap cursor)
492
- '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]' // nested anchor inside adjacent sibling (when next to a widget like gap cursor)
492
+ '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]:first-of-type' // first nested anchor inside adjacent sibling (when next to a widget like gap cursor)
493
493
  ].join(', ');
494
494
  const dragHandlerAnchorStyles = css({
495
495
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
@@ -10,6 +10,7 @@ import { DIRECTION } from '@atlaskit/editor-common/types';
10
10
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
11
11
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
12
12
  import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
13
+ import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
13
14
  import { findChildrenByType, findParentNodeOfType, findParentNodeOfTypeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
14
15
  import { findTable, isInTable, isTableSelected } from '@atlaskit/editor-tables/utils';
15
16
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -420,7 +421,11 @@ export var moveNode = function moveNode(api) {
420
421
  if (inputMethod === INPUT_METHOD.DRAG_AND_DROP) {
421
422
  tr = setCursorPositionAtMovedNode(tr, mappedTo, api);
422
423
  } else if (preservedSelection) {
423
- // do nothing here to allow the selection preservation plugin to handle mapping the selection
424
+ var _currMeta = tr.getMeta(key);
425
+ var nodeMovedOffset = mappedTo - sliceFrom;
426
+ tr.setMeta(key, _objectSpread(_objectSpread({}, _currMeta), {}, {
427
+ preservedSelectionMapping: new Mapping([new StepMap([0, 0, nodeMovedOffset])])
428
+ }));
424
429
  } else if (isMultiSelect) {
425
430
  var _api$blockControls$co;
426
431
  tr = (_api$blockControls$co = api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(mappedTo, mappedTo + sliceSize)({
@@ -431,8 +436,7 @@ export var moveNode = function moveNode(api) {
431
436
  }
432
437
  var currMeta = tr.getMeta(key);
433
438
  tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
434
- nodeMoved: true,
435
- nodeMovedOffset: mappedTo - sliceFrom
439
+ nodeMoved: true
436
440
  }));
437
441
  api === null || api === void 0 || api.core.actions.focus();
438
442
  var $mappedTo = tr.doc.resolve(mappedTo);
@@ -25,7 +25,7 @@ var getNodeSelector = function getNodeSelector(ignoreNodes, ignoreNodeDescendant
25
25
  var ignoreNodeDescendantsSelectorList = ignoreNodeDescendants.map(function (node) {
26
26
  if (node === 'table') {
27
27
  // Special case for table to exclude its direct descendants
28
- return ["[data-prosemirror-node-name=\"tableCell\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > [data-node-anchor]"];
28
+ return ["[data-prosemirror-node-name=\"tableCell\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableCell\"] > *:not([data-node-anchor]) > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > [data-node-anchor]", "[data-prosemirror-node-name=\"tableHeader\"] > *:not([data-node-anchor]) > [data-node-anchor]"];
29
29
  }
30
30
  return "[data-prosemirror-node-name=\"".concat(node, "\"] [data-node-anchor]");
31
31
  });
@@ -1,6 +1,5 @@
1
1
  import { expandToBlockRange } from '@atlaskit/editor-common/selection';
2
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
4
3
  import { getBlockControlsMeta, key } from '../main';
5
4
  import { collapseToSelectionRange } from './getSelection';
6
5
  export var getMultiSelectionIfPosInside = function getMultiSelectionIfPosInside(api, pos, tr) {
@@ -85,9 +84,8 @@ export var alignAnchorHeadInDirectionOfPos = function alignAnchorHeadInDirection
85
84
  */
86
85
  export var mapPreservedSelection = function mapPreservedSelection(selection, tr) {
87
86
  var _ref = getBlockControlsMeta(tr) || {},
88
- nodeMoved = _ref.nodeMoved,
89
- nodeMovedOffset = _ref.nodeMovedOffset;
90
- var mapping = nodeMoved && typeof nodeMovedOffset === 'number' ? new Mapping([new StepMap([0, 0, nodeMovedOffset])]) : tr.mapping;
87
+ preservedSelectionMapping = _ref.preservedSelectionMapping;
88
+ var mapping = preservedSelectionMapping || tr.mapping;
91
89
  if (selection instanceof TextSelection) {
92
90
  var from = mapping.map(selection.from);
93
91
  var to = mapping.map(selection.to);
@@ -400,11 +400,11 @@ var blockCardWithoutLayout = css({
400
400
  });
401
401
  var nextAnchorSelector = ['&[data-node-anchor]',
402
402
  // adjacent sibling with anchor
403
- '&:not([data-node-anchor]) [data-node-anchor]',
404
- // nested anchor inside adjacent sibling
403
+ '&:not([data-node-anchor]) [data-node-anchor]:first-of-type',
404
+ // first nested anchor inside adjacent sibling
405
405
  '&.ProseMirror-widget + [data-node-anchor]',
406
406
  // adjacent sibling with anchor (when next to a widget like gap cursor)
407
- '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]' // nested anchor inside adjacent sibling (when next to a widget like gap cursor)
407
+ '&.ProseMirror-widget + :not([data-node-anchor]) [data-node-anchor]:first-of-type' // first nested anchor inside adjacent sibling (when next to a widget like gap cursor)
408
408
  ].join(', ');
409
409
  var dragHandlerAnchorStyles = css({
410
410
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
@@ -15,6 +15,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
15
15
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
16
16
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
17
17
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
18
+ import { type Mapping } from '@atlaskit/editor-prosemirror/transform';
18
19
  import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
19
20
  export type ActiveNode = {
20
21
  anchorName: string;
@@ -162,7 +163,7 @@ export type BlockControlsMeta = {
162
163
  editorBlurred: boolean;
163
164
  editorHeight: number;
164
165
  nodeMoved: boolean;
165
- nodeMovedOffset: number;
166
+ preservedSelectionMapping: Mapping;
166
167
  type: string;
167
168
  };
168
169
  export type MoveNodeMethod = INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT | INPUT_METHOD.BLOCK_MENU;
@@ -15,6 +15,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
15
15
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
16
16
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
17
17
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
18
+ import { type Mapping } from '@atlaskit/editor-prosemirror/transform';
18
19
  import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
19
20
  export type ActiveNode = {
20
21
  anchorName: string;
@@ -162,7 +163,7 @@ export type BlockControlsMeta = {
162
163
  editorBlurred: boolean;
163
164
  editorHeight: number;
164
165
  nodeMoved: boolean;
165
- nodeMovedOffset: number;
166
+ preservedSelectionMapping: Mapping;
166
167
  type: string;
167
168
  };
168
169
  export type MoveNodeMethod = INPUT_METHOD.DRAG_AND_DROP | INPUT_METHOD.SHORTCUT | INPUT_METHOD.BLOCK_MENU;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "7.12.0",
3
+ "version": "7.13.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-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.6.0",
57
+ "@atlaskit/tmp-editor-statsig": "^14.7.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.38.0",
69
+ "@atlaskit/editor-common": "^110.39.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"