@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
|
@@ -19,6 +19,7 @@ import { isEmptyDocument } from '@atlaskit/editor-common/utils';
|
|
|
19
19
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
20
20
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
21
21
|
import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
22
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
22
23
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
23
24
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
24
25
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/utils/combine';
|
|
@@ -233,13 +234,14 @@ var getDecorationAtPos = function getDecorationAtPos(state, decorations, pos, to
|
|
|
233
234
|
return nodeDecAtActivePos;
|
|
234
235
|
};
|
|
235
236
|
var _apply = function apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
236
|
-
var
|
|
237
|
+
var _meta$multiSelectDnD, _api$editorViewMode, _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;
|
|
237
238
|
var rightSideControlsEnabled = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
238
239
|
var quickInsertButtonEnabled = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : true;
|
|
239
240
|
var anchorRectCache = arguments.length > 10 ? arguments[10] : undefined;
|
|
240
241
|
var resizeObserverWidth = arguments.length > 11 ? arguments[11] : undefined;
|
|
241
242
|
var pragmaticCleanup = arguments.length > 12 ? arguments[12] : undefined;
|
|
242
243
|
var resolvedSurfaces = arguments.length > 13 && arguments[13] !== undefined ? arguments[13] : [];
|
|
244
|
+
var limitedModeTeardown = arguments.length > 14 ? arguments[14] : undefined;
|
|
243
245
|
var activeNode = currentState.activeNode,
|
|
244
246
|
decorations = currentState.decorations,
|
|
245
247
|
isResizerResizing = currentState.isResizerResizing,
|
|
@@ -266,18 +268,67 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
|
|
|
266
268
|
isAllText = _getTrMetadata.isAllText,
|
|
267
269
|
isReplacedWithSameSize = _getTrMetadata.isReplacedWithSameSize;
|
|
268
270
|
var meta = tr.getMeta(key);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
271
|
+
if (isExperimentEnabled('platform_editor_dynamic_limited_mode')) {
|
|
272
|
+
var _api$limitedMode;
|
|
273
|
+
// Both arms read `newState` — the state this transaction is producing. Deriving `enabled` from
|
|
274
|
+
// `sharedState.currentState()` instead would resolve against `view.state`, which during `apply` is
|
|
275
|
+
// still the *previous* state, delaying the limited-mode teardown by one transaction.
|
|
276
|
+
//
|
|
277
|
+
// Limited mode can now also be latched at runtime by the performance detector, so the treatment
|
|
278
|
+
// arm considers both reasons rather than just the document one. Identical in the control arm, where
|
|
279
|
+
// the runtime latch can never be set.
|
|
280
|
+
var limitedModeState = api === null || api === void 0 || (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 || (_api$limitedMode = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode === void 0 ? void 0 : _api$limitedMode.limitedModePluginKey.getState(newState);
|
|
281
|
+
if (!!(limitedModeState !== null && limitedModeState !== void 0 && limitedModeState.enabled)) {
|
|
282
|
+
/**
|
|
283
|
+
* INFO: This is a duplicate of the logic in destroy(). When we enter limited mode we want to
|
|
284
|
+
* trigger the cleanup logic in destroy().
|
|
285
|
+
*/
|
|
286
|
+
if (!limitedModeTeardown || !limitedModeTeardown.done) {
|
|
287
|
+
var _getDocument$querySel2, _getDocument2;
|
|
288
|
+
/**
|
|
289
|
+
* Edge-triggered under the experiment: limited mode is a latch, so without this guard the
|
|
290
|
+
* teardown re-runs on every subsequent transaction for the rest of the session — and would
|
|
291
|
+
* re-register the pragmatic monitors if `pragmaticCleanup` ever became re-entrant.
|
|
292
|
+
*/
|
|
293
|
+
if (limitedModeTeardown) {
|
|
294
|
+
limitedModeTeardown.done = true;
|
|
295
|
+
}
|
|
296
|
+
var 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;
|
|
297
|
+
if (editorContentArea && resizeObserverWidth) {
|
|
298
|
+
resizeObserverWidth.unobserve(editorContentArea);
|
|
299
|
+
}
|
|
300
|
+
pragmaticCleanup === null || pragmaticCleanup === void 0 || pragmaticCleanup();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Reset rather than freeze. Returning `currentState` here would keep `decorations`,
|
|
305
|
+
* `activeNode` and the multi-select positions from before the latch, while skipping the
|
|
306
|
+
* `tr.mapping` remapping below — so they would silently drift out of sync with the document on
|
|
307
|
+
* every subsequent edit. Nothing renders them in limited mode (`props.decorations` returns
|
|
308
|
+
* early), but stale positions are a latent source of incorrect offsets for anything that reads
|
|
309
|
+
* them, so the safe state is empty.
|
|
310
|
+
*/
|
|
311
|
+
return _objectSpread(_objectSpread({}, currentState), {}, {
|
|
312
|
+
activeNode: undefined,
|
|
313
|
+
decorations: DecorationSet.empty,
|
|
314
|
+
multiSelectDnD: undefined
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
var _api$limitedMode2;
|
|
319
|
+
var hasDocumentSizeBreachedThreshold = api === null || api === void 0 || (_api$limitedMode2 = api.limitedMode) === null || _api$limitedMode2 === void 0 || (_api$limitedMode2 = _api$limitedMode2.sharedState.currentState()) === null || _api$limitedMode2 === void 0 || (_api$limitedMode2 = _api$limitedMode2.limitedModePluginKey.getState(newState)) === null || _api$limitedMode2 === void 0 ? void 0 : _api$limitedMode2.documentSizeBreachesThreshold;
|
|
320
|
+
if (hasDocumentSizeBreachedThreshold) {
|
|
321
|
+
var _getDocument$querySel3, _getDocument3;
|
|
322
|
+
/**
|
|
323
|
+
* 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().
|
|
324
|
+
*/
|
|
325
|
+
var _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;
|
|
326
|
+
if (_editorContentArea && resizeObserverWidth) {
|
|
327
|
+
resizeObserverWidth.unobserve(_editorContentArea);
|
|
328
|
+
}
|
|
329
|
+
pragmaticCleanup === null || pragmaticCleanup === void 0 || pragmaticCleanup();
|
|
330
|
+
return currentState;
|
|
278
331
|
}
|
|
279
|
-
pragmaticCleanup === null || pragmaticCleanup === void 0 || pragmaticCleanup();
|
|
280
|
-
return currentState;
|
|
281
332
|
}
|
|
282
333
|
|
|
283
334
|
// When steps exist, remap existing decorations, activeNode and multi select positions
|
|
@@ -906,6 +957,10 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
906
957
|
}
|
|
907
958
|
var resizeObserverWidth;
|
|
908
959
|
var pragmaticCleanup = null;
|
|
960
|
+
// Limited mode is a one-way latch, so its teardown must only run on the transition.
|
|
961
|
+
var limitedModeTeardown = {
|
|
962
|
+
done: false
|
|
963
|
+
};
|
|
909
964
|
return new SafePlugin({
|
|
910
965
|
key: key,
|
|
911
966
|
state: {
|
|
@@ -915,13 +970,13 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
915
970
|
});
|
|
916
971
|
},
|
|
917
972
|
apply: function apply(tr, currentState, _, newState) {
|
|
918
|
-
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces);
|
|
973
|
+
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces, limitedModeTeardown);
|
|
919
974
|
}
|
|
920
975
|
},
|
|
921
976
|
props: {
|
|
922
977
|
decorations: function decorations(state) {
|
|
923
|
-
var _api$
|
|
924
|
-
if (api !== null && api !== void 0 && (_api$
|
|
978
|
+
var _api$limitedMode3, _api$editorDisabled, _key$getState2, _api$editorViewMode3;
|
|
979
|
+
if (api !== null && api !== void 0 && (_api$limitedMode3 = api.limitedMode) !== null && _api$limitedMode3 !== void 0 && (_api$limitedMode3 = _api$limitedMode3.sharedState.currentState()) !== null && _api$limitedMode3 !== void 0 && _api$limitedMode3.enabled) {
|
|
925
980
|
return;
|
|
926
981
|
}
|
|
927
982
|
var isDisabled = api === null || api === void 0 || (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 || (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.editorDisabled;
|
|
@@ -994,8 +1049,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
994
1049
|
return false;
|
|
995
1050
|
},
|
|
996
1051
|
dragenter: function dragenter(view, event) {
|
|
997
|
-
var _api$
|
|
998
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1052
|
+
var _api$limitedMode4, _key$getState3;
|
|
1053
|
+
if (api !== null && api !== void 0 && (_api$limitedMode4 = api.limitedMode) !== null && _api$limitedMode4 !== void 0 && (_api$limitedMode4 = _api$limitedMode4.sharedState.currentState()) !== null && _api$limitedMode4 !== void 0 && _api$limitedMode4.enabled) {
|
|
999
1054
|
return;
|
|
1000
1055
|
}
|
|
1001
1056
|
|
|
@@ -1035,8 +1090,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1035
1090
|
}
|
|
1036
1091
|
},
|
|
1037
1092
|
dragstart: function dragstart(view) {
|
|
1038
|
-
var _api$
|
|
1039
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1093
|
+
var _api$limitedMode5, _anchorRectCache2;
|
|
1094
|
+
if (api !== null && api !== void 0 && (_api$limitedMode5 = api.limitedMode) !== null && _api$limitedMode5 !== void 0 && (_api$limitedMode5 = _api$limitedMode5.sharedState.currentState()) !== null && _api$limitedMode5 !== void 0 && _api$limitedMode5.enabled) {
|
|
1040
1095
|
return;
|
|
1041
1096
|
}
|
|
1042
1097
|
startMeasure(EDITOR_BLOCKS_DRAG_INIT);
|
|
@@ -1053,8 +1108,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1053
1108
|
})));
|
|
1054
1109
|
},
|
|
1055
1110
|
dragend: function dragend(view) {
|
|
1056
|
-
var _api$
|
|
1057
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1111
|
+
var _api$limitedMode6, _key$getState4;
|
|
1112
|
+
if (api !== null && api !== void 0 && (_api$limitedMode6 = api.limitedMode) !== null && _api$limitedMode6 !== void 0 && (_api$limitedMode6 = _api$limitedMode6.sharedState.currentState()) !== null && _api$limitedMode6 !== void 0 && _api$limitedMode6.enabled) {
|
|
1058
1113
|
return;
|
|
1059
1114
|
}
|
|
1060
1115
|
var state = view.state,
|
|
@@ -1074,8 +1129,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1074
1129
|
}
|
|
1075
1130
|
},
|
|
1076
1131
|
mouseover: function mouseover(view, event) {
|
|
1077
|
-
var _api$
|
|
1078
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1132
|
+
var _api$limitedMode7, _getNodeIdProvider;
|
|
1133
|
+
if (api !== null && api !== void 0 && (_api$limitedMode7 = api.limitedMode) !== null && _api$limitedMode7 !== void 0 && (_api$limitedMode7 = _api$limitedMode7.sharedState.currentState()) !== null && _api$limitedMode7 !== void 0 && _api$limitedMode7.enabled) {
|
|
1079
1134
|
return;
|
|
1080
1135
|
}
|
|
1081
1136
|
|
|
@@ -1089,15 +1144,15 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1089
1144
|
return false;
|
|
1090
1145
|
},
|
|
1091
1146
|
mousedown: function mousedown(view, event) {
|
|
1092
|
-
var _api$
|
|
1093
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1147
|
+
var _api$limitedMode8;
|
|
1148
|
+
if (api !== null && api !== void 0 && (_api$limitedMode8 = api.limitedMode) !== null && _api$limitedMode8 !== void 0 && (_api$limitedMode8 = _api$limitedMode8.sharedState.currentState()) !== null && _api$limitedMode8 !== void 0 && _api$limitedMode8.enabled) {
|
|
1094
1149
|
return;
|
|
1095
1150
|
}
|
|
1096
1151
|
return editorExperiment('platform_editor_controls', 'variant1') ? handleMouseDown(api)(view, event) : undefined;
|
|
1097
1152
|
},
|
|
1098
1153
|
keydown: function keydown(view, event) {
|
|
1099
|
-
var _api$
|
|
1100
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1154
|
+
var _api$limitedMode9;
|
|
1155
|
+
if (api !== null && api !== void 0 && (_api$limitedMode9 = api.limitedMode) !== null && _api$limitedMode9 !== void 0 && (_api$limitedMode9 = _api$limitedMode9.sharedState.currentState()) !== null && _api$limitedMode9 !== void 0 && _api$limitedMode9.enabled) {
|
|
1101
1156
|
return;
|
|
1102
1157
|
}
|
|
1103
1158
|
if (event.shiftKey && event.ctrlKey) {
|
|
@@ -1128,8 +1183,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1128
1183
|
return false;
|
|
1129
1184
|
},
|
|
1130
1185
|
keyup: function keyup(view, event) {
|
|
1131
|
-
var _api$
|
|
1132
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1186
|
+
var _api$limitedMode0;
|
|
1187
|
+
if (api !== null && api !== void 0 && (_api$limitedMode0 = api.limitedMode) !== null && _api$limitedMode0 !== void 0 && (_api$limitedMode0 = _api$limitedMode0.sharedState.currentState()) !== null && _api$limitedMode0 !== void 0 && _api$limitedMode0.enabled) {
|
|
1133
1188
|
return;
|
|
1134
1189
|
}
|
|
1135
1190
|
if (!event.repeat && event.key === 'Shift') {
|
|
@@ -1139,8 +1194,8 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1139
1194
|
}
|
|
1140
1195
|
},
|
|
1141
1196
|
blur: function blur(view, event) {
|
|
1142
|
-
var _api$
|
|
1143
|
-
if (api !== null && api !== void 0 && (_api$
|
|
1197
|
+
var _api$limitedMode1;
|
|
1198
|
+
if (api !== null && api !== void 0 && (_api$limitedMode1 = api.limitedMode) !== null && _api$limitedMode1 !== void 0 && (_api$limitedMode1 = _api$limitedMode1.sharedState.currentState()) !== null && _api$limitedMode1 !== void 0 && _api$limitedMode1.enabled) {
|
|
1144
1199
|
return;
|
|
1145
1200
|
}
|
|
1146
1201
|
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
@@ -1187,13 +1242,13 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
1187
1242
|
// Registry surfaces have their own ResizeObservers and absolute placement.
|
|
1188
1243
|
// Width metadata only drives legacy widget recreation.
|
|
1189
1244
|
if (legacyDragHandleEnabled && !isResizerResizing) {
|
|
1190
|
-
var
|
|
1245
|
+
var _editorContentArea2 = entries[0].target;
|
|
1191
1246
|
// Ignored via go/ees005
|
|
1192
1247
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1193
|
-
var editorWidthRight =
|
|
1248
|
+
var editorWidthRight = _editorContentArea2.getBoundingClientRect().right;
|
|
1194
1249
|
// Ignored via go/ees005
|
|
1195
1250
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1196
|
-
var editorWidthLeft =
|
|
1251
|
+
var editorWidthLeft = _editorContentArea2.getBoundingClientRect().left;
|
|
1197
1252
|
transaction.setMeta(key, _objectSpread(_objectSpread({}, transaction.getMeta(key)), {}, {
|
|
1198
1253
|
editorWidthLeft: editorWidthLeft,
|
|
1199
1254
|
editorWidthRight: editorWidthRight
|
|
@@ -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
|
-
},
|
|
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:
|
|
53
|
+
components: hoverOnlyComponents,
|
|
54
54
|
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
55
55
|
surfaceContext: surfaceContext
|
|
56
|
-
})),
|
|
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:
|
|
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>,
|
|
@@ -19,7 +19,9 @@ export interface FlagType {
|
|
|
19
19
|
toolbarFlagsEnabled: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
|
|
22
|
-
export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null, resolvedSurfaces?: readonly ResolvedSurface[]
|
|
22
|
+
export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null, resolvedSurfaces?: readonly ResolvedSurface[], limitedModeTeardown?: {
|
|
23
|
+
done: boolean;
|
|
24
|
+
}) => PluginState | {
|
|
23
25
|
activeDropTargetNode: ActiveDropTargetNode | undefined;
|
|
24
26
|
activeNode: any;
|
|
25
27
|
blockMenuOptions: {
|
|
@@ -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.
|
|
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,11 +26,12 @@
|
|
|
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",
|
|
32
33
|
"@atlaskit/editor-plugin-interaction": "^28.0.0",
|
|
33
|
-
"@atlaskit/editor-plugin-limited-mode": "^14.
|
|
34
|
+
"@atlaskit/editor-plugin-limited-mode": "^14.1.0",
|
|
34
35
|
"@atlaskit/editor-plugin-metrics": "^18.0.0",
|
|
35
36
|
"@atlaskit/editor-plugin-quick-insert": "^17.0.0",
|
|
36
37
|
"@atlaskit/editor-plugin-selection": "^17.0.0",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"uuid": "^11.1.1"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@atlaskit/editor-common": "^121.
|
|
71
|
+
"@atlaskit/editor-common": "^121.1.0",
|
|
71
72
|
"react": "^18.2.0 || ^19.2.0",
|
|
72
73
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
73
74
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|