@atlaskit/editor-plugin-block-controls 18.0.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 +51 -0
- package/dist/cjs/editor-commands/move-node.js +11 -0
- package/dist/cjs/editor-commands/move-to-layout.js +8 -0
- package/dist/cjs/pm-plugins/main.js +89 -34
- package/dist/cjs/pm-plugins/utils/collapsed-heading.js +69 -0
- package/dist/cjs/ui/block-controls-left-surface.js +5 -4
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +10 -0
- package/dist/cjs/ui/use-block-controls-surface-drag-source.js +11 -0
- package/dist/es2019/editor-commands/move-node.js +11 -0
- package/dist/es2019/editor-commands/move-to-layout.js +8 -0
- package/dist/es2019/pm-plugins/main.js +87 -32
- package/dist/es2019/pm-plugins/utils/collapsed-heading.js +65 -0
- package/dist/es2019/ui/block-controls-left-surface.js +5 -4
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +10 -0
- package/dist/es2019/ui/use-block-controls-surface-drag-source.js +11 -0
- package/dist/esm/editor-commands/move-node.js +11 -0
- package/dist/esm/editor-commands/move-to-layout.js +8 -0
- package/dist/esm/pm-plugins/main.js +89 -34
- package/dist/esm/pm-plugins/utils/collapsed-heading.js +63 -0
- package/dist/esm/ui/block-controls-left-surface.js +5 -4
- package/dist/esm/ui/block-controls-surface-drag-handle.js +10 -0
- package/dist/esm/ui/use-block-controls-surface-drag-source.js +11 -0
- package/dist/types/blockControlsPluginType.d.ts +2 -0
- package/dist/types/pm-plugins/main.d.ts +3 -1
- package/dist/types/pm-plugins/utils/collapsed-heading.d.ts +27 -0
- package/package.json +4 -3
|
@@ -13,6 +13,7 @@ import { isEmptyDocument } from '@atlaskit/editor-common/utils';
|
|
|
13
13
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
14
14
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
15
15
|
import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
16
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
16
17
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
17
18
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
18
19
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/utils/combine';
|
|
@@ -231,8 +232,8 @@ const getDecorationAtPos = (state, decorations, pos, to) => {
|
|
|
231
232
|
const nodeDecAtActivePos = nodeDecsAtActivePos.pop();
|
|
232
233
|
return nodeDecAtActivePos;
|
|
233
234
|
};
|
|
234
|
-
export const apply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled = false, quickInsertButtonEnabled = true, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces = []) => {
|
|
235
|
-
var
|
|
235
|
+
export const apply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled = false, quickInsertButtonEnabled = true, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces = [], limitedModeTeardown) => {
|
|
236
|
+
var _meta$multiSelectDnD, _api$editorViewMode, _api$editorViewMode$s, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging2, _meta$isDragging3, _meta$toggleMenu, _meta$toggleMenu2, _meta$toggleMenu3, _meta$toggleMenu4, _meta$toggleMenu5, _meta$toggleMenu6, _meta$toggleMenu7, _meta$toggleMenu8, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
|
|
236
237
|
let {
|
|
237
238
|
activeNode,
|
|
238
239
|
decorations,
|
|
@@ -264,18 +265,68 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
|
|
|
264
265
|
isReplacedWithSameSize
|
|
265
266
|
} = getTrMetadata(tr, flags);
|
|
266
267
|
const meta = tr.getMeta(key);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
268
|
+
if (isExperimentEnabled('platform_editor_dynamic_limited_mode')) {
|
|
269
|
+
var _api$limitedMode, _api$limitedMode$shar;
|
|
270
|
+
// Both arms read `newState` — the state this transaction is producing. Deriving `enabled` from
|
|
271
|
+
// `sharedState.currentState()` instead would resolve against `view.state`, which during `apply` is
|
|
272
|
+
// still the *previous* state, delaying the limited-mode teardown by one transaction.
|
|
273
|
+
//
|
|
274
|
+
// Limited mode can now also be latched at runtime by the performance detector, so the treatment
|
|
275
|
+
// arm considers both reasons rather than just the document one. Identical in the control arm, where
|
|
276
|
+
// the runtime latch can never be set.
|
|
277
|
+
const limitedModeState = api === null || api === void 0 ? void 0 : (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 ? void 0 : (_api$limitedMode$shar = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode$shar === void 0 ? void 0 : _api$limitedMode$shar.limitedModePluginKey.getState(newState);
|
|
278
|
+
if (!!(limitedModeState !== null && limitedModeState !== void 0 && limitedModeState.enabled)) {
|
|
279
|
+
/**
|
|
280
|
+
* INFO: This is a duplicate of the logic in destroy(). When we enter limited mode we want to
|
|
281
|
+
* trigger the cleanup logic in destroy().
|
|
282
|
+
*/
|
|
283
|
+
if (!limitedModeTeardown || !limitedModeTeardown.done) {
|
|
284
|
+
var _getDocument$querySel2, _getDocument2;
|
|
285
|
+
/**
|
|
286
|
+
* Edge-triggered under the experiment: limited mode is a latch, so without this guard the
|
|
287
|
+
* teardown re-runs on every subsequent transaction for the rest of the session — and would
|
|
288
|
+
* re-register the pragmatic monitors if `pragmaticCleanup` ever became re-entrant.
|
|
289
|
+
*/
|
|
290
|
+
if (limitedModeTeardown) {
|
|
291
|
+
limitedModeTeardown.done = true;
|
|
292
|
+
}
|
|
293
|
+
const editorContentArea = (_getDocument$querySel2 = (_getDocument2 = getDocument()) === null || _getDocument2 === void 0 ? void 0 : _getDocument2.querySelector('.fabric-editor-popup-scroll-parent')) !== null && _getDocument$querySel2 !== void 0 ? _getDocument$querySel2 : null;
|
|
294
|
+
if (editorContentArea && resizeObserverWidth) {
|
|
295
|
+
resizeObserverWidth.unobserve(editorContentArea);
|
|
296
|
+
}
|
|
297
|
+
pragmaticCleanup === null || pragmaticCleanup === void 0 ? void 0 : pragmaticCleanup();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Reset rather than freeze. Returning `currentState` here would keep `decorations`,
|
|
302
|
+
* `activeNode` and the multi-select positions from before the latch, while skipping the
|
|
303
|
+
* `tr.mapping` remapping below — so they would silently drift out of sync with the document on
|
|
304
|
+
* every subsequent edit. Nothing renders them in limited mode (`props.decorations` returns
|
|
305
|
+
* early), but stale positions are a latent source of incorrect offsets for anything that reads
|
|
306
|
+
* them, so the safe state is empty.
|
|
307
|
+
*/
|
|
308
|
+
return {
|
|
309
|
+
...currentState,
|
|
310
|
+
activeNode: undefined,
|
|
311
|
+
decorations: DecorationSet.empty,
|
|
312
|
+
multiSelectDnD: undefined
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
var _api$limitedMode2, _api$limitedMode2$sha, _api$limitedMode2$sha2;
|
|
317
|
+
const hasDocumentSizeBreachedThreshold = api === null || api === void 0 ? void 0 : (_api$limitedMode2 = api.limitedMode) === null || _api$limitedMode2 === void 0 ? void 0 : (_api$limitedMode2$sha = _api$limitedMode2.sharedState.currentState()) === null || _api$limitedMode2$sha === void 0 ? void 0 : (_api$limitedMode2$sha2 = _api$limitedMode2$sha.limitedModePluginKey.getState(newState)) === null || _api$limitedMode2$sha2 === void 0 ? void 0 : _api$limitedMode2$sha2.documentSizeBreachesThreshold;
|
|
318
|
+
if (hasDocumentSizeBreachedThreshold) {
|
|
319
|
+
var _getDocument$querySel3, _getDocument3;
|
|
320
|
+
/**
|
|
321
|
+
* INFO: This if statement is a duplicate of the logic in destroy(). When the threshold is breached and we enter limited mode, we want to trigger the cleanup logic in destroy().
|
|
322
|
+
*/
|
|
323
|
+
const editorContentArea = (_getDocument$querySel3 = (_getDocument3 = getDocument()) === null || _getDocument3 === void 0 ? void 0 : _getDocument3.querySelector('.fabric-editor-popup-scroll-parent')) !== null && _getDocument$querySel3 !== void 0 ? _getDocument$querySel3 : null;
|
|
324
|
+
if (editorContentArea && resizeObserverWidth) {
|
|
325
|
+
resizeObserverWidth.unobserve(editorContentArea);
|
|
326
|
+
}
|
|
327
|
+
pragmaticCleanup === null || pragmaticCleanup === void 0 ? void 0 : pragmaticCleanup();
|
|
328
|
+
return currentState;
|
|
276
329
|
}
|
|
277
|
-
pragmaticCleanup === null || pragmaticCleanup === void 0 ? void 0 : pragmaticCleanup();
|
|
278
|
-
return currentState;
|
|
279
330
|
}
|
|
280
331
|
|
|
281
332
|
// When steps exist, remap existing decorations, activeNode and multi select positions
|
|
@@ -810,6 +861,10 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
810
861
|
}
|
|
811
862
|
let resizeObserverWidth;
|
|
812
863
|
let pragmaticCleanup = null;
|
|
864
|
+
// Limited mode is a one-way latch, so its teardown must only run on the transition.
|
|
865
|
+
const limitedModeTeardown = {
|
|
866
|
+
done: false
|
|
867
|
+
};
|
|
813
868
|
return new SafePlugin({
|
|
814
869
|
key,
|
|
815
870
|
state: {
|
|
@@ -819,12 +874,12 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
819
874
|
surfaceNodePositions: resolvedSurfaces.length > 0 ? getSurfaceNodePositions(editorState, resolvedSurfaces) : []
|
|
820
875
|
};
|
|
821
876
|
},
|
|
822
|
-
apply: (tr, currentState, _, newState) => apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces)
|
|
877
|
+
apply: (tr, currentState, _, newState) => apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces, limitedModeTeardown)
|
|
823
878
|
},
|
|
824
879
|
props: {
|
|
825
880
|
decorations: state => {
|
|
826
|
-
var _api$
|
|
827
|
-
if (api !== null && api !== void 0 && (_api$
|
|
881
|
+
var _api$limitedMode3, _api$limitedMode3$sha, _api$editorDisabled, _api$editorDisabled$s, _key$getState2, _api$editorViewMode3, _api$editorViewMode3$;
|
|
882
|
+
if (api !== null && api !== void 0 && (_api$limitedMode3 = api.limitedMode) !== null && _api$limitedMode3 !== void 0 && (_api$limitedMode3$sha = _api$limitedMode3.sharedState.currentState()) !== null && _api$limitedMode3$sha !== void 0 && _api$limitedMode3$sha.enabled) {
|
|
828
883
|
return;
|
|
829
884
|
}
|
|
830
885
|
const isDisabled = api === null || api === void 0 ? void 0 : (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 ? void 0 : (_api$editorDisabled$s = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled$s === void 0 ? void 0 : _api$editorDisabled$s.editorDisabled;
|
|
@@ -900,8 +955,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
900
955
|
return false;
|
|
901
956
|
},
|
|
902
957
|
dragenter(view, event) {
|
|
903
|
-
var _api$
|
|
904
|
-
if (api !== null && api !== void 0 && (_api$
|
|
958
|
+
var _api$limitedMode4, _api$limitedMode4$sha, _key$getState3;
|
|
959
|
+
if (api !== null && api !== void 0 && (_api$limitedMode4 = api.limitedMode) !== null && _api$limitedMode4 !== void 0 && (_api$limitedMode4$sha = _api$limitedMode4.sharedState.currentState()) !== null && _api$limitedMode4$sha !== void 0 && _api$limitedMode4$sha.enabled) {
|
|
905
960
|
return;
|
|
906
961
|
}
|
|
907
962
|
|
|
@@ -941,8 +996,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
941
996
|
}
|
|
942
997
|
},
|
|
943
998
|
dragstart(view) {
|
|
944
|
-
var _api$
|
|
945
|
-
if (api !== null && api !== void 0 && (_api$
|
|
999
|
+
var _api$limitedMode5, _api$limitedMode5$sha, _anchorRectCache2;
|
|
1000
|
+
if (api !== null && api !== void 0 && (_api$limitedMode5 = api.limitedMode) !== null && _api$limitedMode5 !== void 0 && (_api$limitedMode5$sha = _api$limitedMode5.sharedState.currentState()) !== null && _api$limitedMode5$sha !== void 0 && _api$limitedMode5$sha.enabled) {
|
|
946
1001
|
return;
|
|
947
1002
|
}
|
|
948
1003
|
startMeasure(EDITOR_BLOCKS_DRAG_INIT);
|
|
@@ -960,8 +1015,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
960
1015
|
}));
|
|
961
1016
|
},
|
|
962
1017
|
dragend(view) {
|
|
963
|
-
var _api$
|
|
964
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1018
|
+
var _api$limitedMode6, _api$limitedMode6$sha, _key$getState4;
|
|
1019
|
+
if (api !== null && api !== void 0 && (_api$limitedMode6 = api.limitedMode) !== null && _api$limitedMode6 !== void 0 && (_api$limitedMode6$sha = _api$limitedMode6.sharedState.currentState()) !== null && _api$limitedMode6$sha !== void 0 && _api$limitedMode6$sha.enabled) {
|
|
965
1020
|
return;
|
|
966
1021
|
}
|
|
967
1022
|
const {
|
|
@@ -984,8 +1039,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
984
1039
|
}
|
|
985
1040
|
},
|
|
986
1041
|
mouseover: (view, event) => {
|
|
987
|
-
var _api$
|
|
988
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1042
|
+
var _api$limitedMode7, _api$limitedMode7$sha, _getNodeIdProvider;
|
|
1043
|
+
if (api !== null && api !== void 0 && (_api$limitedMode7 = api.limitedMode) !== null && _api$limitedMode7 !== void 0 && (_api$limitedMode7$sha = _api$limitedMode7.sharedState.currentState()) !== null && _api$limitedMode7$sha !== void 0 && _api$limitedMode7$sha.enabled) {
|
|
989
1044
|
return;
|
|
990
1045
|
}
|
|
991
1046
|
|
|
@@ -999,15 +1054,15 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
999
1054
|
return false;
|
|
1000
1055
|
},
|
|
1001
1056
|
mousedown: (view, event) => {
|
|
1002
|
-
var _api$
|
|
1003
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1057
|
+
var _api$limitedMode8, _api$limitedMode8$sha;
|
|
1058
|
+
if (api !== null && api !== void 0 && (_api$limitedMode8 = api.limitedMode) !== null && _api$limitedMode8 !== void 0 && (_api$limitedMode8$sha = _api$limitedMode8.sharedState.currentState()) !== null && _api$limitedMode8$sha !== void 0 && _api$limitedMode8$sha.enabled) {
|
|
1004
1059
|
return;
|
|
1005
1060
|
}
|
|
1006
1061
|
return editorExperiment('platform_editor_controls', 'variant1') ? handleMouseDown(api)(view, event) : undefined;
|
|
1007
1062
|
},
|
|
1008
1063
|
keydown(view, event) {
|
|
1009
|
-
var _api$
|
|
1010
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1064
|
+
var _api$limitedMode9, _api$limitedMode9$sha;
|
|
1065
|
+
if (api !== null && api !== void 0 && (_api$limitedMode9 = api.limitedMode) !== null && _api$limitedMode9 !== void 0 && (_api$limitedMode9$sha = _api$limitedMode9.sharedState.currentState()) !== null && _api$limitedMode9$sha !== void 0 && _api$limitedMode9$sha.enabled) {
|
|
1011
1066
|
return;
|
|
1012
1067
|
}
|
|
1013
1068
|
if (event.shiftKey && event.ctrlKey) {
|
|
@@ -1039,8 +1094,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
1039
1094
|
return false;
|
|
1040
1095
|
},
|
|
1041
1096
|
keyup(view, event) {
|
|
1042
|
-
var _api$
|
|
1043
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1097
|
+
var _api$limitedMode0, _api$limitedMode0$sha;
|
|
1098
|
+
if (api !== null && api !== void 0 && (_api$limitedMode0 = api.limitedMode) !== null && _api$limitedMode0 !== void 0 && (_api$limitedMode0$sha = _api$limitedMode0.sharedState.currentState()) !== null && _api$limitedMode0$sha !== void 0 && _api$limitedMode0$sha.enabled) {
|
|
1044
1099
|
return;
|
|
1045
1100
|
}
|
|
1046
1101
|
if (!event.repeat && event.key === 'Shift') {
|
|
@@ -1051,8 +1106,8 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI, nodeDecora
|
|
|
1051
1106
|
}
|
|
1052
1107
|
},
|
|
1053
1108
|
blur(view, event) {
|
|
1054
|
-
var _api$
|
|
1055
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1109
|
+
var _api$limitedMode1, _api$limitedMode1$sha;
|
|
1110
|
+
if (api !== null && api !== void 0 && (_api$limitedMode1 = api.limitedMode) !== null && _api$limitedMode1 !== void 0 && (_api$limitedMode1$sha = _api$limitedMode1.sharedState.currentState()) !== null && _api$limitedMode1$sha !== void 0 && _api$limitedMode1$sha.enabled) {
|
|
1056
1111
|
return;
|
|
1057
1112
|
}
|
|
1058
1113
|
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
@@ -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
|
-
},
|
|
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:
|
|
55
|
+
components: hoverOnlyComponents,
|
|
56
56
|
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
57
57
|
surfaceContext: surfaceContext
|
|
58
|
-
})),
|
|
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:
|
|
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,
|