@atlaskit/editor-plugin-block-controls 28.0.5 → 29.0.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,19 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 29.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 28.0.6
10
+
11
+ ### Patch Changes
12
+
13
+ - [`de7c546c5c8f6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/de7c546c5c8f6) -
14
+ Unmount drag handle React roots when ProseMirror removes the widget, fixing a leak of roots and
15
+ event listeners. Behind the `platform_editor_reduce_memory_leaks` experiment.
16
+
3
17
  ## 28.0.5
4
18
 
5
19
  ### Patch Changes
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _react = require("react");
10
10
  var _uuid = require("uuid");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
12
13
  var _fg = require("@atlaskit/platform-feature-flags/fg");
13
14
  var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
14
15
  var _consts = require("../ui/consts");
@@ -16,8 +17,8 @@ var _dragHandle = require("../ui/drag-handle");
16
17
  var _decorationsCommon = require("./decorations-common");
17
18
  var _reactRootRegistry = require("./react-root-registry");
18
19
  var _marks = require("./utils/marks");
19
- // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
20
-
20
+ 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; }
21
+ 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) { (0, _defineProperty2.default)(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; } // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
21
22
  var TYPE_ACTIVE_HANDLE_DEC = exports.TYPE_ACTIVE_HANDLE_DEC = 'active-drag-handle-node';
22
23
 
23
24
  /**
@@ -49,6 +50,14 @@ var findHandleDec = exports.findHandleDec = function findHandleDec(decorations,
49
50
  return spec.type === _decorationsCommon.TYPE_HANDLE_DEC;
50
51
  });
51
52
  };
53
+ // Unmounting a focused handle runs its effect cleanup (view.focus()), which steals focus from the
54
+ // open block menu. The root is left mounted in that case.
55
+ var unmountUnlessMenuOpen = function unmountUnlessMenuOpen(api, element) {
56
+ var _api$blockControls;
57
+ if (!(api !== null && api !== void 0 && (_api$blockControls = api.blockControls) !== null && _api$blockControls !== void 0 && (_api$blockControls = _api$blockControls.sharedState.currentState()) !== null && _api$blockControls !== void 0 && _api$blockControls.isMenuOpen)) {
58
+ (0, _reactRootRegistry.unmountFromMountPoint)(element);
59
+ }
60
+ };
52
61
  var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(_ref) {
53
62
  var api = _ref.api,
54
63
  formatMessage = _ref.formatMessage,
@@ -62,7 +71,7 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
62
71
  (0, _decorationsCommon.unmountDecorations)(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
63
72
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
64
73
  var key = (0, _uuid.v4)();
65
- var widgetSpec = {
74
+ var widgetSpec = _objectSpread({
66
75
  side: -1,
67
76
  type: _decorationsCommon.TYPE_HANDLE_DEC,
68
77
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -73,7 +82,14 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
73
82
  * Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
74
83
  */
75
84
  marks: (0, _marks.getMatchingBlockMarks)(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize])
76
- };
85
+ }, (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_reduce_memory_leaks') && {
86
+ destroy: function destroy(node) {
87
+ // Deferred: unmounting a root during a React render warns
88
+ queueMicrotask(function () {
89
+ return unmountUnlessMenuOpen(api, node);
90
+ });
91
+ }
92
+ });
77
93
  return _view.Decoration.widget(pos, function (view, getPosUnsafe) {
78
94
  var element = document.createElement('span');
79
95
  // inline decoration causes focus issues when refocusing Editor into first line
@@ -2,12 +2,13 @@ import { createElement } from 'react';
2
2
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
3
3
  import { v4 as uuid } from 'uuid';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
6
  import { fg } from '@atlaskit/platform-feature-flags/fg';
6
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
7
8
  import { ACTIVE_DRAG_HANDLE_ATTR } from '../ui/consts';
8
9
  import { DragHandle, DragHandleWithVisibility } from '../ui/drag-handle';
9
10
  import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
10
- import { renderToMountPoint } from './react-root-registry';
11
+ import { renderToMountPoint, unmountFromMountPoint } from './react-root-registry';
11
12
  import { getMatchingBlockMarks } from './utils/marks';
12
13
  export const TYPE_ACTIVE_HANDLE_DEC = 'active-drag-handle-node';
13
14
 
@@ -35,6 +36,14 @@ export const emptyParagraphNodeDecorations = () => {
35
36
  export const findHandleDec = (decorations, from, to) => {
36
37
  return decorations.find(from, to, spec => spec.type === TYPE_HANDLE_DEC);
37
38
  };
39
+ // Unmounting a focused handle runs its effect cleanup (view.focus()), which steals focus from the
40
+ // open block menu. The root is left mounted in that case.
41
+ const unmountUnlessMenuOpen = (api, element) => {
42
+ var _api$blockControls, _api$blockControls$sh;
43
+ if (!(api !== null && api !== void 0 && (_api$blockControls = api.blockControls) !== null && _api$blockControls !== void 0 && (_api$blockControls$sh = _api$blockControls.sharedState.currentState()) !== null && _api$blockControls$sh !== void 0 && _api$blockControls$sh.isMenuOpen)) {
44
+ unmountFromMountPoint(element);
45
+ }
46
+ };
38
47
  export const dragHandleDecoration = ({
39
48
  api,
40
49
  formatMessage,
@@ -59,7 +68,13 @@ export const dragHandleDecoration = ({
59
68
  * Exclude 'breakout' on purpose, so the widgets render at the top of the document to avoid z-index issues
60
69
  * Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
61
70
  */
62
- marks: getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize])
71
+ marks: getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize]),
72
+ ...(isExperimentEnabled('platform_editor_reduce_memory_leaks') && {
73
+ destroy: node => {
74
+ // Deferred: unmounting a root during a React render warns
75
+ queueMicrotask(() => unmountUnlessMenuOpen(api, node));
76
+ }
77
+ })
63
78
  };
64
79
  return Decoration.widget(pos, (view, getPosUnsafe) => {
65
80
  const element = document.createElement('span');
@@ -1,14 +1,17 @@
1
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; }
2
4
  import { createElement } from 'react';
3
5
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
4
6
  import { v4 as uuid } from 'uuid';
5
7
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
6
9
  import { fg } from '@atlaskit/platform-feature-flags/fg';
7
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
8
11
  import { ACTIVE_DRAG_HANDLE_ATTR } from '../ui/consts';
9
12
  import { DragHandle, DragHandleWithVisibility } from '../ui/drag-handle';
10
13
  import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
11
- import { renderToMountPoint } from './react-root-registry';
14
+ import { renderToMountPoint, unmountFromMountPoint } from './react-root-registry';
12
15
  import { getMatchingBlockMarks } from './utils/marks';
13
16
  export var TYPE_ACTIVE_HANDLE_DEC = 'active-drag-handle-node';
14
17
 
@@ -41,6 +44,14 @@ export var findHandleDec = function findHandleDec(decorations, from, to) {
41
44
  return spec.type === TYPE_HANDLE_DEC;
42
45
  });
43
46
  };
47
+ // Unmounting a focused handle runs its effect cleanup (view.focus()), which steals focus from the
48
+ // open block menu. The root is left mounted in that case.
49
+ var unmountUnlessMenuOpen = function unmountUnlessMenuOpen(api, element) {
50
+ var _api$blockControls;
51
+ if (!(api !== null && api !== void 0 && (_api$blockControls = api.blockControls) !== null && _api$blockControls !== void 0 && (_api$blockControls = _api$blockControls.sharedState.currentState()) !== null && _api$blockControls !== void 0 && _api$blockControls.isMenuOpen)) {
52
+ unmountFromMountPoint(element);
53
+ }
54
+ };
44
55
  export var dragHandleDecoration = function dragHandleDecoration(_ref) {
45
56
  var api = _ref.api,
46
57
  formatMessage = _ref.formatMessage,
@@ -54,7 +65,7 @@ export var dragHandleDecoration = function dragHandleDecoration(_ref) {
54
65
  unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
55
66
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
56
67
  var key = uuid();
57
- var widgetSpec = {
68
+ var widgetSpec = _objectSpread({
58
69
  side: -1,
59
70
  type: TYPE_HANDLE_DEC,
60
71
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -65,7 +76,14 @@ export var dragHandleDecoration = function dragHandleDecoration(_ref) {
65
76
  * Other block marks must be added, otherwise PM will split the DOM elements causing mutations and re-draws
66
77
  */
67
78
  marks: getMatchingBlockMarks(editorState, pos, [editorState.schema.marks.alignment, editorState.schema.marks.fontSize])
68
- };
79
+ }, isExperimentEnabled('platform_editor_reduce_memory_leaks') && {
80
+ destroy: function destroy(node) {
81
+ // Deferred: unmounting a root during a React render warns
82
+ queueMicrotask(function () {
83
+ return unmountUnlessMenuOpen(api, node);
84
+ });
85
+ }
86
+ });
69
87
  return Decoration.widget(pos, function (view, getPosUnsafe) {
70
88
  var element = document.createElement('span');
71
89
  // inline decoration causes focus issues when refocusing Editor into first line
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "28.0.5",
3
+ "version": "29.0.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,25 +29,25 @@
29
29
  "@atlaskit/button": "^25.4.0",
30
30
  "@atlaskit/css": "^1.1.0",
31
31
  "@atlaskit/docs": "^12.3.0",
32
- "@atlaskit/editor-plugin-accessibility-utils": "^27.0.0",
33
- "@atlaskit/editor-plugin-analytics": "^27.0.0",
34
- "@atlaskit/editor-plugin-block-collapse": "^13.0.0",
35
- "@atlaskit/editor-plugin-editor-disabled": "^27.0.0",
36
- "@atlaskit/editor-plugin-editor-viewmode": "^29.0.0",
37
- "@atlaskit/editor-plugin-feature-flags": "^26.0.0",
38
- "@atlaskit/editor-plugin-interaction": "^41.0.0",
39
- "@atlaskit/editor-plugin-limited-mode": "^24.0.0",
40
- "@atlaskit/editor-plugin-metrics": "^28.0.0",
41
- "@atlaskit/editor-plugin-quick-insert": "^27.0.0",
42
- "@atlaskit/editor-plugin-selection": "^27.0.0",
43
- "@atlaskit/editor-plugin-show-diff": "^25.0.0",
44
- "@atlaskit/editor-plugin-toolbar": "^24.0.0",
45
- "@atlaskit/editor-plugin-type-ahead": "^28.0.0",
46
- "@atlaskit/editor-plugin-ui-control-registry": "^21.0.0",
47
- "@atlaskit/editor-plugin-user-intent": "^25.0.0",
48
- "@atlaskit/editor-plugin-width": "^28.0.0",
32
+ "@atlaskit/editor-plugin-accessibility-utils": "^28.0.0",
33
+ "@atlaskit/editor-plugin-analytics": "^28.0.0",
34
+ "@atlaskit/editor-plugin-block-collapse": "^14.0.0",
35
+ "@atlaskit/editor-plugin-editor-disabled": "^28.0.0",
36
+ "@atlaskit/editor-plugin-editor-viewmode": "^30.0.0",
37
+ "@atlaskit/editor-plugin-feature-flags": "^27.0.0",
38
+ "@atlaskit/editor-plugin-interaction": "^42.0.0",
39
+ "@atlaskit/editor-plugin-limited-mode": "^25.0.0",
40
+ "@atlaskit/editor-plugin-metrics": "^29.0.0",
41
+ "@atlaskit/editor-plugin-quick-insert": "^28.0.0",
42
+ "@atlaskit/editor-plugin-selection": "^28.0.0",
43
+ "@atlaskit/editor-plugin-show-diff": "^26.0.0",
44
+ "@atlaskit/editor-plugin-toolbar": "^25.0.0",
45
+ "@atlaskit/editor-plugin-type-ahead": "^29.0.0",
46
+ "@atlaskit/editor-plugin-ui-control-registry": "^22.0.0",
47
+ "@atlaskit/editor-plugin-user-intent": "^26.0.0",
48
+ "@atlaskit/editor-plugin-width": "^29.0.0",
49
49
  "@atlaskit/editor-prosemirror": "^9.0.0",
50
- "@atlaskit/editor-shared-styles": "^4.4.0",
50
+ "@atlaskit/editor-shared-styles": "^4.5.0",
51
51
  "@atlaskit/editor-tables": "^3.2.0",
52
52
  "@atlaskit/editor-ui-control-model": "^2.10.0",
53
53
  "@atlaskit/icon": "^38.0.0",
@@ -58,7 +58,7 @@
58
58
  "@atlaskit/pragmatic-drag-and-drop": "^4.0.0",
59
59
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^3.2.0",
60
60
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^4.2.0",
61
- "@atlaskit/primitives": "^22.5.0",
61
+ "@atlaskit/primitives": "^22.6.0",
62
62
  "@atlaskit/section-message": "^10.2.0",
63
63
  "@atlaskit/theme": "^28.2.0",
64
64
  "@atlaskit/tmp-editor-statsig": "^240.0.0",
@@ -73,7 +73,7 @@
73
73
  "uuid": "^11.1.1"
74
74
  },
75
75
  "peerDependencies": {
76
- "@atlaskit/editor-common": "^131.2.0",
76
+ "@atlaskit/editor-common": "^132.0.0",
77
77
  "react": "^18.2.0 || ^19.2.0",
78
78
  "react-dom": "^18.2.0 || ^19.2.0",
79
79
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"