@atlaskit/editor-plugin-block-controls 18.1.0 → 18.2.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,20 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 18.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`00fc2f11bb42e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/00fc2f11bb42e) -
8
+ [ux] Support dragging and changing the format of complete collapsed heading sections under
9
+ `platform_editor_collapsible_headings`.
10
+
11
+ ### Patch Changes
12
+
13
+ - [`834dc6bee730b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/834dc6bee730b) -
14
+ [ux] Keep collapsed heading controls visible under `platform_editor_collapsible_headings` when
15
+ another editor node is active.
16
+ - Updated dependencies
17
+
3
18
  ## 18.1.0
4
19
 
5
20
  ### Minor Changes
@@ -25,6 +25,7 @@ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
25
25
  var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
26
26
  var _main = require("../pm-plugins/main");
27
27
  var _analytics2 = require("../pm-plugins/utils/analytics");
28
+ var _collapsedHeading = require("../pm-plugins/utils/collapsed-heading");
28
29
  var _getNestedNodePosition = require("../pm-plugins/utils/getNestedNodePosition");
29
30
  var _getSelection = require("../pm-plugins/utils/getSelection");
30
31
  var _removeFromSource = require("../pm-plugins/utils/remove-from-source");
@@ -369,6 +370,7 @@ var moveNode = exports.moveNode = function moveNode(api) {
369
370
  if (!handleNode) {
370
371
  return tr;
371
372
  }
373
+ var wasCollapsedHeading = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings') && (0, _collapsedHeading.isCollapsedHeading)(api, start);
372
374
  var sliceFrom = start;
373
375
  var sliceTo;
374
376
  var sourceNodeTypes, hasSelectedMultipleNodes;
@@ -486,6 +488,15 @@ var moveNode = exports.moveNode = function moveNode(api) {
486
488
  api === null || api === void 0 || api.core.actions.focus();
487
489
  }
488
490
  var $mappedTo = tr.doc.resolve(mappedTo);
491
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings')) {
492
+ (0, _collapsedHeading.updateCollapsedHeadingAfterMove)({
493
+ api: api,
494
+ destinationPos: mappedTo,
495
+ isNested: $mappedTo.parent.type.name !== 'doc',
496
+ tr: tr,
497
+ wasCollapsed: wasCollapsedHeading
498
+ });
499
+ }
489
500
  var expandAncestor = (0, _utils2.findParentNodeOfTypeClosestToPos)($to, [expand, nestedExpand]);
490
501
  if (expandAncestor) {
491
502
  var wasExpandExpanded = _expand.expandedState.get(expandAncestor.node);
@@ -8,10 +8,12 @@ var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _monitoring = require("@atlaskit/editor-common/monitoring");
9
9
  var _model = require("@atlaskit/editor-prosemirror/model");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
11
12
  var _fg = require("@atlaskit/platform-feature-flags/fg");
12
13
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
13
14
  var _analytics2 = require("../pm-plugins/utils/analytics");
14
15
  var _checkFragment = require("../pm-plugins/utils/check-fragment");
16
+ var _collapsedHeading = require("../pm-plugins/utils/collapsed-heading");
15
17
  var _consts = require("../pm-plugins/utils/consts");
16
18
  var _removeFromSource = require("../pm-plugins/utils/remove-from-source");
17
19
  var _selection = require("../pm-plugins/utils/selection");
@@ -243,6 +245,12 @@ var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
243
245
  if (!canMove) {
244
246
  return tr;
245
247
  }
248
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings') && (0, _collapsedHeading.isCollapsedHeading)(api, from)) {
249
+ var _api$blockCollapse;
250
+ (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 || _api$blockCollapse.commands.expandHeading(from)({
251
+ tr: tr
252
+ });
253
+ }
246
254
  var toNode = canMove.toNode,
247
255
  $to = canMove.$to,
248
256
  sourceContent = canMove.sourceContent,
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateCollapsedHeadingAfterMove = exports.prepareCollapsedHeadingSelection = exports.isCollapsedHeading = exports.getCollapsedHeadingRange = void 0;
7
+ /** Document range containing a heading and all content in its section. */
8
+
9
+ /** Returns the full section range when the heading at this position is collapsed. */
10
+ var getCollapsedHeadingRange = exports.getCollapsedHeadingRange = function getCollapsedHeadingRange(api, headingPos) {
11
+ var _api$blockCollapse;
12
+ var sectionEnd = api === null || api === void 0 || (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 || (_api$blockCollapse = _api$blockCollapse.sharedState.currentState()) === null || _api$blockCollapse === void 0 ? void 0 : _api$blockCollapse.collapsedSectionEnds.get(headingPos);
13
+ return sectionEnd === undefined ? undefined : {
14
+ from: headingPos,
15
+ to: sectionEnd
16
+ };
17
+ };
18
+
19
+ /** Returns whether the heading at this position has a collapsed section. */
20
+ var isCollapsedHeading = exports.isCollapsedHeading = function isCollapsedHeading(api, headingPos) {
21
+ var _api$blockCollapse$sh, _api$blockCollapse2;
22
+ return (_api$blockCollapse$sh = api === null || api === void 0 || (_api$blockCollapse2 = api.blockCollapse) === null || _api$blockCollapse2 === void 0 || (_api$blockCollapse2 = _api$blockCollapse2.sharedState.currentState()) === null || _api$blockCollapse2 === void 0 ? void 0 : _api$blockCollapse2.collapsedSectionEnds.has(headingPos)) !== null && _api$blockCollapse$sh !== void 0 ? _api$blockCollapse$sh : false;
23
+ };
24
+
25
+ /** Selects a collapsed section for drag or block-menu operations, optionally expanding it. */
26
+ var prepareCollapsedHeadingSelection = exports.prepareCollapsedHeadingSelection = function prepareCollapsedHeadingSelection(_ref) {
27
+ var _api$blockControls;
28
+ var api = _ref.api,
29
+ expand = _ref.expand,
30
+ headingPos = _ref.headingPos,
31
+ tr = _ref.tr;
32
+ var range = getCollapsedHeadingRange(api, headingPos);
33
+ if (!range) {
34
+ return false;
35
+ }
36
+ if (expand) {
37
+ var _api$blockCollapse3;
38
+ api === null || api === void 0 || (_api$blockCollapse3 = api.blockCollapse) === null || _api$blockCollapse3 === void 0 || _api$blockCollapse3.commands.expandHeading(headingPos)({
39
+ tr: tr
40
+ });
41
+ }
42
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions(range.from, range.to)({
43
+ tr: tr
44
+ });
45
+ return true;
46
+ };
47
+
48
+ /** Preserves collapse for root moves and expands headings moved into nested containers. */
49
+ var updateCollapsedHeadingAfterMove = exports.updateCollapsedHeadingAfterMove = function updateCollapsedHeadingAfterMove(_ref2) {
50
+ var _api$blockCollapse5;
51
+ var api = _ref2.api,
52
+ destinationPos = _ref2.destinationPos,
53
+ isNested = _ref2.isNested,
54
+ tr = _ref2.tr,
55
+ wasCollapsed = _ref2.wasCollapsed;
56
+ if (!wasCollapsed) {
57
+ return;
58
+ }
59
+ if (isNested) {
60
+ var _api$blockCollapse4;
61
+ api === null || api === void 0 || (_api$blockCollapse4 = api.blockCollapse) === null || _api$blockCollapse4 === void 0 || _api$blockCollapse4.commands.expandHeading(destinationPos)({
62
+ tr: tr
63
+ });
64
+ return;
65
+ }
66
+ api === null || api === void 0 || (_api$blockCollapse5 = api.blockCollapse) === null || _api$blockCollapse5 === void 0 || _api$blockCollapse5.commands.collapseHeadingsAtPositions([destinationPos])({
67
+ tr: tr
68
+ });
69
+ };
@@ -51,22 +51,23 @@ var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function Block
51
51
  className: (0, _runtime.ax)(["_kqswstnw _1pbyb4wl"])
52
52
  }, /*#__PURE__*/_react.default.createElement("div", {
53
53
  className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
54
- }, willRenderPersistent && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
54
+ }, willRenderHoverOnly && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
55
55
  api: api,
56
56
  controlSide: (0, _blockControlsSurfaceContext.getBlockControlsSurfaceControlSide)(surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT), (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_controls_reliable_anchor')),
57
57
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
58
58
  shouldUseDisplayContents: true
59
59
  }, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
60
- components: persistentComponents,
60
+ components: hoverOnlyComponents,
61
61
  surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
62
62
  surfaceContext: surfaceContext
63
- })), willRenderHoverOnly && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
63
+ })), willRenderPersistent && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
64
64
  api: api,
65
65
  controlSide: (0, _blockControlsSurfaceContext.getBlockControlsSurfaceControlSide)(surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT), (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_controls_reliable_anchor')),
66
66
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
67
+ isPersistent: true,
67
68
  shouldUseDisplayContents: true
68
69
  }, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
69
- components: hoverOnlyComponents,
70
+ components: persistentComponents,
70
71
  surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
71
72
  surfaceContext: surfaceContext
72
73
  }))));
@@ -21,10 +21,12 @@ var _hooks = require("@atlaskit/editor-common/hooks");
21
21
  var _keymaps = require("@atlaskit/editor-common/keymaps");
22
22
  var _messages = require("@atlaskit/editor-common/messages");
23
23
  var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/core/drag-handle-vertical"));
24
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
24
25
  var _fg = require("@atlaskit/platform-feature-flags/fg");
25
26
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
26
27
  var _Tooltip = _interopRequireDefault(require("@atlaskit/tooltip/Tooltip"));
27
28
  var _pluginKey = require("../pm-plugins/selection-preservation/plugin-key");
29
+ var _collapsedHeading = require("../pm-plugins/utils/collapsed-heading");
28
30
  var _expandAndUpdateSelection = require("../pm-plugins/utils/expand-and-update-selection");
29
31
  var _getSelection = require("../pm-plugins/utils/getSelection");
30
32
  var _blockControlsSurfaceDragHandleUtils = require("./block-controls-surface-drag-handle-utils");
@@ -221,6 +223,14 @@ var BlockControlsSurfaceDragHandle = exports.BlockControlsSurfaceDragHandle = fu
221
223
  startPos: startPos,
222
224
  tr: tr
223
225
  });
226
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings')) {
227
+ (0, _collapsedHeading.prepareCollapsedHeadingSelection)({
228
+ api: api,
229
+ expand: true,
230
+ headingPos: startPos,
231
+ tr: tr
232
+ });
233
+ }
224
234
  api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
225
235
  tr: tr
226
236
  });
@@ -8,10 +8,12 @@ var _react = require("react");
8
8
  var _analytics = require("@atlaskit/editor-common/analytics");
9
9
  var _performanceMeasures = require("@atlaskit/editor-common/performance-measures");
10
10
  var _utils = require("@atlaskit/editor-prosemirror/utils");
11
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
11
12
  var _elementAdapter = require("@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter");
12
13
  var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview");
13
14
  var _activeAnchorTracker = require("../pm-plugins/utils/active-anchor-tracker");
14
15
  var _analytics2 = require("../pm-plugins/utils/analytics");
16
+ var _collapsedHeading = require("../pm-plugins/utils/collapsed-heading");
15
17
  var _getSelection = require("../pm-plugins/utils/getSelection");
16
18
  var _dragPreview = require("./drag-preview");
17
19
  var _blockControlsSurfaceDragHandleUtils = require("./block-controls-surface-drag-handle-utils");
@@ -50,6 +52,15 @@ var useBlockControlsSurfaceDragSource = exports.useBlockControlsSurfaceDragSourc
50
52
  if (typeof handlePos !== 'number') {
51
53
  return tr;
52
54
  }
55
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings') && (0, _collapsedHeading.isCollapsedHeading)(api, handlePos)) {
56
+ (0, _collapsedHeading.prepareCollapsedHeadingSelection)({
57
+ api: api,
58
+ expand: false,
59
+ headingPos: handlePos,
60
+ tr: tr
61
+ });
62
+ return tr;
63
+ }
53
64
  if (!tr.selection.empty && (0, _getSelection.isHandleCorrelatedToSelection)(view.state, tr.selection, handlePos)) {
54
65
  var _api$blockControls;
55
66
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions()({
@@ -17,6 +17,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
17
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
18
18
  import { key } from '../pm-plugins/main';
19
19
  import { attachMoveNodeAnalytics, getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
20
+ import { isCollapsedHeading, updateCollapsedHeadingAfterMove } from '../pm-plugins/utils/collapsed-heading';
20
21
  import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
21
22
  import { setCursorPositionAtMovedNode } from '../pm-plugins/utils/getSelection';
22
23
  import { removeFromSource } from '../pm-plugins/utils/remove-from-source';
@@ -369,6 +370,7 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
369
370
  if (!handleNode) {
370
371
  return tr;
371
372
  }
373
+ const wasCollapsedHeading = isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, start);
372
374
  let sliceFrom = start;
373
375
  let sliceTo;
374
376
  let sourceNodeTypes, hasSelectedMultipleNodes;
@@ -487,6 +489,15 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
487
489
  api === null || api === void 0 ? void 0 : api.core.actions.focus();
488
490
  }
489
491
  const $mappedTo = tr.doc.resolve(mappedTo);
492
+ if (isExperimentEnabled('platform_editor_collapsible_headings')) {
493
+ updateCollapsedHeadingAfterMove({
494
+ api,
495
+ destinationPos: mappedTo,
496
+ isNested: $mappedTo.parent.type.name !== 'doc',
497
+ tr,
498
+ wasCollapsed: wasCollapsedHeading
499
+ });
500
+ }
490
501
  const expandAncestor = findParentNodeOfTypeClosestToPos($to, [expand, nestedExpand]);
491
502
  if (expandAncestor) {
492
503
  const wasExpandExpanded = expandedState.get(expandAncestor.node);
@@ -2,10 +2,12 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
3
  import { Fragment, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
6
  import { fg } from '@atlaskit/platform-feature-flags/fg';
6
7
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
8
  import { attachMoveNodeAnalytics, fireInsertLayoutAnalytics, getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
8
9
  import { containsNodeOfType, isFragmentOfType } from '../pm-plugins/utils/check-fragment';
10
+ import { isCollapsedHeading } from '../pm-plugins/utils/collapsed-heading';
9
11
  import { maxLayoutColumnSupported } from '../pm-plugins/utils/consts';
10
12
  import { removeFromSource } from '../pm-plugins/utils/remove-from-source';
11
13
  import { getMultiSelectionIfPosInside } from '../pm-plugins/utils/selection';
@@ -231,6 +233,12 @@ export const moveToLayout = api => (from, to, options) => ({
231
233
  if (!canMove) {
232
234
  return tr;
233
235
  }
236
+ if (isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, from)) {
237
+ var _api$blockCollapse;
238
+ (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 ? void 0 : _api$blockCollapse.commands.expandHeading(from)({
239
+ tr
240
+ });
241
+ }
234
242
  const {
235
243
  toNode,
236
244
  $to,
@@ -0,0 +1,65 @@
1
+ /** Document range containing a heading and all content in its section. */
2
+
3
+ /** Returns the full section range when the heading at this position is collapsed. */
4
+ export const getCollapsedHeadingRange = (api, headingPos) => {
5
+ var _api$blockCollapse, _api$blockCollapse$sh;
6
+ const sectionEnd = api === null || api === void 0 ? void 0 : (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 ? void 0 : (_api$blockCollapse$sh = _api$blockCollapse.sharedState.currentState()) === null || _api$blockCollapse$sh === void 0 ? void 0 : _api$blockCollapse$sh.collapsedSectionEnds.get(headingPos);
7
+ return sectionEnd === undefined ? undefined : {
8
+ from: headingPos,
9
+ to: sectionEnd
10
+ };
11
+ };
12
+
13
+ /** Returns whether the heading at this position has a collapsed section. */
14
+ export const isCollapsedHeading = (api, headingPos) => {
15
+ var _api$blockCollapse$sh2, _api$blockCollapse2, _api$blockCollapse2$s;
16
+ return (_api$blockCollapse$sh2 = api === null || api === void 0 ? void 0 : (_api$blockCollapse2 = api.blockCollapse) === null || _api$blockCollapse2 === void 0 ? void 0 : (_api$blockCollapse2$s = _api$blockCollapse2.sharedState.currentState()) === null || _api$blockCollapse2$s === void 0 ? void 0 : _api$blockCollapse2$s.collapsedSectionEnds.has(headingPos)) !== null && _api$blockCollapse$sh2 !== void 0 ? _api$blockCollapse$sh2 : false;
17
+ };
18
+
19
+ /** Selects a collapsed section for drag or block-menu operations, optionally expanding it. */
20
+ export const prepareCollapsedHeadingSelection = ({
21
+ api,
22
+ expand,
23
+ headingPos,
24
+ tr
25
+ }) => {
26
+ var _api$blockControls;
27
+ const range = getCollapsedHeadingRange(api, headingPos);
28
+ if (!range) {
29
+ return false;
30
+ }
31
+ if (expand) {
32
+ var _api$blockCollapse3;
33
+ api === null || api === void 0 ? void 0 : (_api$blockCollapse3 = api.blockCollapse) === null || _api$blockCollapse3 === void 0 ? void 0 : _api$blockCollapse3.commands.expandHeading(headingPos)({
34
+ tr
35
+ });
36
+ }
37
+ api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setMultiSelectPositions(range.from, range.to)({
38
+ tr
39
+ });
40
+ return true;
41
+ };
42
+
43
+ /** Preserves collapse for root moves and expands headings moved into nested containers. */
44
+ export const updateCollapsedHeadingAfterMove = ({
45
+ api,
46
+ destinationPos,
47
+ isNested,
48
+ tr,
49
+ wasCollapsed
50
+ }) => {
51
+ var _api$blockCollapse5;
52
+ if (!wasCollapsed) {
53
+ return;
54
+ }
55
+ if (isNested) {
56
+ var _api$blockCollapse4;
57
+ api === null || api === void 0 ? void 0 : (_api$blockCollapse4 = api.blockCollapse) === null || _api$blockCollapse4 === void 0 ? void 0 : _api$blockCollapse4.commands.expandHeading(destinationPos)({
58
+ tr
59
+ });
60
+ return;
61
+ }
62
+ api === null || api === void 0 ? void 0 : (_api$blockCollapse5 = api.blockCollapse) === null || _api$blockCollapse5 === void 0 ? void 0 : _api$blockCollapse5.commands.collapseHeadingsAtPositions([destinationPos])({
63
+ tr
64
+ });
65
+ };
@@ -46,22 +46,23 @@ export const BlockControlsLeftSurface = ({
46
46
  className: ax(["_kqswstnw _1pbyb4wl"])
47
47
  }, /*#__PURE__*/React.createElement("div", {
48
48
  className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
49
- }, willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
49
+ }, willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
50
50
  api: api,
51
51
  controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
52
52
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
53
53
  shouldUseDisplayContents: true
54
54
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
55
- components: persistentComponents,
55
+ components: hoverOnlyComponents,
56
56
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
57
57
  surfaceContext: surfaceContext
58
- })), willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
58
+ })), willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
59
59
  api: api,
60
60
  controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
61
61
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
62
+ isPersistent: true,
62
63
  shouldUseDisplayContents: true
63
64
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
64
- components: hoverOnlyComponents,
65
+ components: persistentComponents,
65
66
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
66
67
  surfaceContext: surfaceContext
67
68
  }))));
@@ -15,10 +15,12 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
15
15
  import { TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
16
16
  import { blockControlsMessages } from '@atlaskit/editor-common/messages';
17
17
  import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
18
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
18
19
  import { fg } from '@atlaskit/platform-feature-flags/fg';
19
20
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
20
21
  import Tooltip from '@atlaskit/tooltip/Tooltip';
21
22
  import { selectionPreservationPluginKey } from '../pm-plugins/selection-preservation/plugin-key';
23
+ import { prepareCollapsedHeadingSelection } from '../pm-plugins/utils/collapsed-heading';
22
24
  import { expandAndUpdateSelection } from '../pm-plugins/utils/expand-and-update-selection';
23
25
  import { isHandleCorrelatedToSelection } from '../pm-plugins/utils/getSelection';
24
26
  import { buildLayoutColumnMenuMeta } from './block-controls-surface-drag-handle-utils';
@@ -211,6 +213,14 @@ export const BlockControlsSurfaceDragHandle = ({
211
213
  startPos,
212
214
  tr
213
215
  });
216
+ if (isExperimentEnabled('platform_editor_collapsible_headings')) {
217
+ prepareCollapsedHeadingSelection({
218
+ api,
219
+ expand: true,
220
+ headingPos: startPos,
221
+ tr
222
+ });
223
+ }
214
224
  api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.startPreservingSelection()({
215
225
  tr
216
226
  });
@@ -2,10 +2,12 @@ import { useEffect } from 'react';
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
3
  import { startMeasure } from '@atlaskit/editor-common/performance-measures';
4
4
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter';
6
7
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview';
7
8
  import { defaultActiveAnchorTracker } from '../pm-plugins/utils/active-anchor-tracker';
8
9
  import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
10
+ import { isCollapsedHeading, prepareCollapsedHeadingSelection } from '../pm-plugins/utils/collapsed-heading';
9
11
  import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
10
12
  import { dragPreview } from './drag-preview';
11
13
  import { getNodeMarginsForDragPreview, getNodeSpacingForDragPreview } from './block-controls-surface-drag-handle-utils';
@@ -45,6 +47,15 @@ export const useBlockControlsSurfaceDragSource = ({
45
47
  if (typeof handlePos !== 'number') {
46
48
  return tr;
47
49
  }
50
+ if (isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, handlePos)) {
51
+ prepareCollapsedHeadingSelection({
52
+ api,
53
+ expand: false,
54
+ headingPos: handlePos,
55
+ tr
56
+ });
57
+ return tr;
58
+ }
48
59
  if (!tr.selection.empty && isHandleCorrelatedToSelection(view.state, tr.selection, handlePos)) {
49
60
  var _api$blockControls;
50
61
  api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setMultiSelectPositions()({
@@ -20,6 +20,7 @@ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
20
20
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
21
21
  import { key } from '../pm-plugins/main';
22
22
  import { attachMoveNodeAnalytics, getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
23
+ import { isCollapsedHeading, updateCollapsedHeadingAfterMove } from '../pm-plugins/utils/collapsed-heading';
23
24
  import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
24
25
  import { setCursorPositionAtMovedNode } from '../pm-plugins/utils/getSelection';
25
26
  import { removeFromSource } from '../pm-plugins/utils/remove-from-source';
@@ -363,6 +364,7 @@ export var moveNode = function moveNode(api) {
363
364
  if (!handleNode) {
364
365
  return tr;
365
366
  }
367
+ var wasCollapsedHeading = isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, start);
366
368
  var sliceFrom = start;
367
369
  var sliceTo;
368
370
  var sourceNodeTypes, hasSelectedMultipleNodes;
@@ -480,6 +482,15 @@ export var moveNode = function moveNode(api) {
480
482
  api === null || api === void 0 || api.core.actions.focus();
481
483
  }
482
484
  var $mappedTo = tr.doc.resolve(mappedTo);
485
+ if (isExperimentEnabled('platform_editor_collapsible_headings')) {
486
+ updateCollapsedHeadingAfterMove({
487
+ api: api,
488
+ destinationPos: mappedTo,
489
+ isNested: $mappedTo.parent.type.name !== 'doc',
490
+ tr: tr,
491
+ wasCollapsed: wasCollapsedHeading
492
+ });
493
+ }
483
494
  var expandAncestor = findParentNodeOfTypeClosestToPos($to, [expand, nestedExpand]);
484
495
  if (expandAncestor) {
485
496
  var wasExpandExpanded = expandedState.get(expandAncestor.node);
@@ -2,10 +2,12 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
3
  import { Fragment, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
6
  import { fg } from '@atlaskit/platform-feature-flags/fg';
6
7
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
8
  import { attachMoveNodeAnalytics, fireInsertLayoutAnalytics, getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
8
9
  import { containsNodeOfType, isFragmentOfType } from '../pm-plugins/utils/check-fragment';
10
+ import { isCollapsedHeading } from '../pm-plugins/utils/collapsed-heading';
9
11
  import { maxLayoutColumnSupported } from '../pm-plugins/utils/consts';
10
12
  import { removeFromSource } from '../pm-plugins/utils/remove-from-source';
11
13
  import { getMultiSelectionIfPosInside } from '../pm-plugins/utils/selection';
@@ -237,6 +239,12 @@ export var moveToLayout = function moveToLayout(api) {
237
239
  if (!canMove) {
238
240
  return tr;
239
241
  }
242
+ if (isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, from)) {
243
+ var _api$blockCollapse;
244
+ (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 || _api$blockCollapse.commands.expandHeading(from)({
245
+ tr: tr
246
+ });
247
+ }
240
248
  var toNode = canMove.toNode,
241
249
  $to = canMove.$to,
242
250
  sourceContent = canMove.sourceContent,
@@ -0,0 +1,63 @@
1
+ /** Document range containing a heading and all content in its section. */
2
+
3
+ /** Returns the full section range when the heading at this position is collapsed. */
4
+ export var getCollapsedHeadingRange = function getCollapsedHeadingRange(api, headingPos) {
5
+ var _api$blockCollapse;
6
+ var sectionEnd = api === null || api === void 0 || (_api$blockCollapse = api.blockCollapse) === null || _api$blockCollapse === void 0 || (_api$blockCollapse = _api$blockCollapse.sharedState.currentState()) === null || _api$blockCollapse === void 0 ? void 0 : _api$blockCollapse.collapsedSectionEnds.get(headingPos);
7
+ return sectionEnd === undefined ? undefined : {
8
+ from: headingPos,
9
+ to: sectionEnd
10
+ };
11
+ };
12
+
13
+ /** Returns whether the heading at this position has a collapsed section. */
14
+ export var isCollapsedHeading = function isCollapsedHeading(api, headingPos) {
15
+ var _api$blockCollapse$sh, _api$blockCollapse2;
16
+ return (_api$blockCollapse$sh = api === null || api === void 0 || (_api$blockCollapse2 = api.blockCollapse) === null || _api$blockCollapse2 === void 0 || (_api$blockCollapse2 = _api$blockCollapse2.sharedState.currentState()) === null || _api$blockCollapse2 === void 0 ? void 0 : _api$blockCollapse2.collapsedSectionEnds.has(headingPos)) !== null && _api$blockCollapse$sh !== void 0 ? _api$blockCollapse$sh : false;
17
+ };
18
+
19
+ /** Selects a collapsed section for drag or block-menu operations, optionally expanding it. */
20
+ export var prepareCollapsedHeadingSelection = function prepareCollapsedHeadingSelection(_ref) {
21
+ var _api$blockControls;
22
+ var api = _ref.api,
23
+ expand = _ref.expand,
24
+ headingPos = _ref.headingPos,
25
+ tr = _ref.tr;
26
+ var range = getCollapsedHeadingRange(api, headingPos);
27
+ if (!range) {
28
+ return false;
29
+ }
30
+ if (expand) {
31
+ var _api$blockCollapse3;
32
+ api === null || api === void 0 || (_api$blockCollapse3 = api.blockCollapse) === null || _api$blockCollapse3 === void 0 || _api$blockCollapse3.commands.expandHeading(headingPos)({
33
+ tr: tr
34
+ });
35
+ }
36
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions(range.from, range.to)({
37
+ tr: tr
38
+ });
39
+ return true;
40
+ };
41
+
42
+ /** Preserves collapse for root moves and expands headings moved into nested containers. */
43
+ export var updateCollapsedHeadingAfterMove = function updateCollapsedHeadingAfterMove(_ref2) {
44
+ var _api$blockCollapse5;
45
+ var api = _ref2.api,
46
+ destinationPos = _ref2.destinationPos,
47
+ isNested = _ref2.isNested,
48
+ tr = _ref2.tr,
49
+ wasCollapsed = _ref2.wasCollapsed;
50
+ if (!wasCollapsed) {
51
+ return;
52
+ }
53
+ if (isNested) {
54
+ var _api$blockCollapse4;
55
+ api === null || api === void 0 || (_api$blockCollapse4 = api.blockCollapse) === null || _api$blockCollapse4 === void 0 || _api$blockCollapse4.commands.expandHeading(destinationPos)({
56
+ tr: tr
57
+ });
58
+ return;
59
+ }
60
+ api === null || api === void 0 || (_api$blockCollapse5 = api.blockCollapse) === null || _api$blockCollapse5 === void 0 || _api$blockCollapse5.commands.collapseHeadingsAtPositions([destinationPos])({
61
+ tr: tr
62
+ });
63
+ };
@@ -44,22 +44,23 @@ export var BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
44
44
  className: ax(["_kqswstnw _1pbyb4wl"])
45
45
  }, /*#__PURE__*/React.createElement("div", {
46
46
  className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
47
- }, willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
47
+ }, willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
48
48
  api: api,
49
49
  controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
50
50
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
51
51
  shouldUseDisplayContents: true
52
52
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
53
- components: persistentComponents,
53
+ components: hoverOnlyComponents,
54
54
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
55
55
  surfaceContext: surfaceContext
56
- })), willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
56
+ })), willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
57
57
  api: api,
58
58
  controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
59
59
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
60
+ isPersistent: true,
60
61
  shouldUseDisplayContents: true
61
62
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
62
- components: hoverOnlyComponents,
63
+ components: persistentComponents,
63
64
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
64
65
  surfaceContext: surfaceContext
65
66
  }))));
@@ -16,10 +16,12 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
16
16
  import { TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
17
17
  import { blockControlsMessages } from '@atlaskit/editor-common/messages';
18
18
  import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
19
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
19
20
  import { fg } from '@atlaskit/platform-feature-flags/fg';
20
21
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
21
22
  import Tooltip from '@atlaskit/tooltip/Tooltip';
22
23
  import { selectionPreservationPluginKey } from '../pm-plugins/selection-preservation/plugin-key';
24
+ import { prepareCollapsedHeadingSelection } from '../pm-plugins/utils/collapsed-heading';
23
25
  import { expandAndUpdateSelection } from '../pm-plugins/utils/expand-and-update-selection';
24
26
  import { isHandleCorrelatedToSelection } from '../pm-plugins/utils/getSelection';
25
27
  import { buildLayoutColumnMenuMeta } from './block-controls-surface-drag-handle-utils';
@@ -215,6 +217,14 @@ export var BlockControlsSurfaceDragHandle = function BlockControlsSurfaceDragHan
215
217
  startPos: startPos,
216
218
  tr: tr
217
219
  });
220
+ if (isExperimentEnabled('platform_editor_collapsible_headings')) {
221
+ prepareCollapsedHeadingSelection({
222
+ api: api,
223
+ expand: true,
224
+ headingPos: startPos,
225
+ tr: tr
226
+ });
227
+ }
218
228
  api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
219
229
  tr: tr
220
230
  });
@@ -2,10 +2,12 @@ import { useEffect } from 'react';
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
3
  import { startMeasure } from '@atlaskit/editor-common/performance-measures';
4
4
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter';
6
7
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview';
7
8
  import { defaultActiveAnchorTracker } from '../pm-plugins/utils/active-anchor-tracker';
8
9
  import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
10
+ import { isCollapsedHeading, prepareCollapsedHeadingSelection } from '../pm-plugins/utils/collapsed-heading';
9
11
  import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
10
12
  import { dragPreview } from './drag-preview';
11
13
  import { getNodeMarginsForDragPreview, getNodeSpacingForDragPreview } from './block-controls-surface-drag-handle-utils';
@@ -44,6 +46,15 @@ export var useBlockControlsSurfaceDragSource = function useBlockControlsSurfaceD
44
46
  if (typeof handlePos !== 'number') {
45
47
  return tr;
46
48
  }
49
+ if (isExperimentEnabled('platform_editor_collapsible_headings') && isCollapsedHeading(api, handlePos)) {
50
+ prepareCollapsedHeadingSelection({
51
+ api: api,
52
+ expand: false,
53
+ headingPos: handlePos,
54
+ tr: tr
55
+ });
56
+ return tr;
57
+ }
47
58
  if (!tr.selection.empty && isHandleCorrelatedToSelection(view.state, tr.selection, handlePos)) {
48
59
  var _api$blockControls;
49
60
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions()({
@@ -4,6 +4,7 @@ import type { PortalProviderAPI } from '@atlaskit/editor-common/portal';
4
4
  import type { DIRECTION, EditorCommand, NextEditorPlugin, OptionalPlugin, PublicPluginAPI } from '@atlaskit/editor-common/types';
5
5
  import type { AccessibilityUtilsPlugin } from '@atlaskit/editor-plugin-accessibility-utils';
6
6
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
7
+ import type { BlockCollapsePlugin } from '@atlaskit/editor-plugin-block-collapse/blockCollapsePluginType';
7
8
  import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
8
9
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
9
10
  import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
@@ -152,6 +153,7 @@ export type NodeDecorationFactory = {
152
153
  };
153
154
  export type MoveNode = (start: number, to: number, inputMethod?: MoveNodeMethod, formatMessage?: IntlShape['formatMessage']) => EditorCommand;
154
155
  export type BlockControlsPluginDependencies = [
156
+ OptionalPlugin<BlockCollapsePlugin>,
155
157
  OptionalPlugin<LimitedModePlugin>,
156
158
  OptionalPlugin<EditorDisabledPlugin>,
157
159
  OptionalPlugin<EditorViewModePlugin>,
@@ -0,0 +1,27 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import type { BlockControlsPlugin } from '../../blockControlsPluginType';
4
+ /** Document range containing a heading and all content in its section. */
5
+ export type CollapsedHeadingRange = {
6
+ from: number;
7
+ to: number;
8
+ };
9
+ /** Returns the full section range when the heading at this position is collapsed. */
10
+ export declare const getCollapsedHeadingRange: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, headingPos: number) => CollapsedHeadingRange | undefined;
11
+ /** Returns whether the heading at this position has a collapsed section. */
12
+ export declare const isCollapsedHeading: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, headingPos: number) => boolean;
13
+ /** Selects a collapsed section for drag or block-menu operations, optionally expanding it. */
14
+ export declare const prepareCollapsedHeadingSelection: ({ api, expand, headingPos, tr, }: {
15
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
16
+ expand: boolean;
17
+ headingPos: number;
18
+ tr: Transaction;
19
+ }) => boolean;
20
+ /** Preserves collapse for root moves and expands headings moved into nested containers. */
21
+ export declare const updateCollapsedHeadingAfterMove: ({ api, destinationPos, isNested, tr, wasCollapsed, }: {
22
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
23
+ destinationPos: number;
24
+ isNested: boolean;
25
+ tr: Transaction;
26
+ wasCollapsed: boolean;
27
+ }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "18.1.0",
3
+ "version": "18.2.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -26,6 +26,7 @@
26
26
  "@atlaskit/docs": "^12.2.0",
27
27
  "@atlaskit/editor-plugin-accessibility-utils": "^17.0.0",
28
28
  "@atlaskit/editor-plugin-analytics": "^17.0.0",
29
+ "@atlaskit/editor-plugin-block-collapse": "^3.1.0",
29
30
  "@atlaskit/editor-plugin-editor-disabled": "^17.0.0",
30
31
  "@atlaskit/editor-plugin-editor-viewmode": "^19.0.0",
31
32
  "@atlaskit/editor-plugin-feature-flags": "^16.0.0",