@atlaskit/editor-plugin-block-controls 3.4.0 → 3.5.1
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 +16 -0
- package/dist/cjs/pm-plugins/decorations-quick-insert-button.js +1 -1
- package/dist/cjs/pm-plugins/main.js +36 -21
- package/dist/cjs/pm-plugins/utils/transactions.js +21 -1
- package/dist/cjs/ui/drag-handle.js +5 -2
- package/dist/es2019/pm-plugins/decorations-quick-insert-button.js +1 -1
- package/dist/es2019/pm-plugins/main.js +36 -21
- package/dist/es2019/pm-plugins/utils/transactions.js +21 -1
- package/dist/es2019/ui/drag-handle.js +5 -2
- package/dist/esm/pm-plugins/decorations-quick-insert-button.js +1 -1
- package/dist/esm/pm-plugins/main.js +36 -21
- package/dist/esm/pm-plugins/utils/transactions.js +21 -1
- package/dist/esm/ui/drag-handle.js +5 -2
- package/dist/types/pm-plugins/utils/transactions.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/utils/transactions.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 3.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#128258](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/128258)
|
|
8
|
+
[`99b0f3de4fdf4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/99b0f3de4fdf4) -
|
|
9
|
+
Update logic for remapping decorations for nodes to fix issues where anchorName is no longer valid
|
|
10
|
+
|
|
11
|
+
## 3.5.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#128788](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/128788)
|
|
16
|
+
[`83a4d1ba203b0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/83a4d1ba203b0) -
|
|
17
|
+
[ux] update icons
|
|
18
|
+
|
|
3
19
|
## 3.4.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -187,7 +187,7 @@ var getDecorationAtPos = function getDecorationAtPos(decorations, pos, to) {
|
|
|
187
187
|
return nodeDecAtActivePos;
|
|
188
188
|
};
|
|
189
189
|
var newApply = exports.newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache) {
|
|
190
|
-
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging,
|
|
190
|
+
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging, _meta$isDragging2, _meta$toggleMenu, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
|
|
191
191
|
var activeNode = currentState.activeNode,
|
|
192
192
|
decorations = currentState.decorations,
|
|
193
193
|
isResizerResizing = currentState.isResizerResizing,
|
|
@@ -202,14 +202,20 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
202
202
|
isShiftDown = currentState.isShiftDown,
|
|
203
203
|
lastDragCancelled = currentState.lastDragCancelled;
|
|
204
204
|
var isActiveNodeDeleted = false;
|
|
205
|
+
var _getTrMetadata = (0, _transactions.getTrMetadata)(tr),
|
|
206
|
+
from = _getTrMetadata.from,
|
|
207
|
+
to = _getTrMetadata.to,
|
|
208
|
+
numReplaceSteps = _getTrMetadata.numReplaceSteps,
|
|
209
|
+
isAllText = _getTrMetadata.isAllText,
|
|
210
|
+
isReplacedWithSameSize = _getTrMetadata.isReplacedWithSameSize;
|
|
205
211
|
|
|
206
212
|
// When steps exist, remap existing decorations, activeNode and multi select positions
|
|
207
213
|
if (tr.docChanged) {
|
|
208
214
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
209
215
|
if (activeNode) {
|
|
210
|
-
var mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
211
|
-
isActiveNodeDeleted = mappedPos.deleted;
|
|
212
216
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
|
|
217
|
+
var mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
218
|
+
isActiveNodeDeleted = mappedPos.deleted;
|
|
213
219
|
activeNode = {
|
|
214
220
|
pos: mappedPos.pos,
|
|
215
221
|
anchorName: activeNode.anchorName,
|
|
@@ -217,13 +223,15 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
217
223
|
};
|
|
218
224
|
} else {
|
|
219
225
|
var _mappedRootPos$pos, _mappedRootPos;
|
|
226
|
+
var _mappedPos = tr.mapping.mapResult(activeNode.pos, -1);
|
|
227
|
+
isActiveNodeDeleted = _mappedPos.deletedAfter;
|
|
220
228
|
// for editor controls, remap the rootPos as well
|
|
221
229
|
var mappedRootPos;
|
|
222
230
|
if (activeNode.rootPos !== undefined) {
|
|
223
|
-
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos);
|
|
231
|
+
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos, -1);
|
|
224
232
|
}
|
|
225
233
|
activeNode = {
|
|
226
|
-
pos:
|
|
234
|
+
pos: _mappedPos.pos,
|
|
227
235
|
anchorName: activeNode.anchorName,
|
|
228
236
|
nodeType: activeNode.nodeType,
|
|
229
237
|
rootPos: (_mappedRootPos$pos = (_mappedRootPos = mappedRootPos) === null || _mappedRootPos === void 0 ? void 0 : _mappedRootPos.pos) !== null && _mappedRootPos$pos !== void 0 ? _mappedRootPos$pos : activeNode.rootPos,
|
|
@@ -244,16 +252,11 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
244
252
|
if (multiSelectDnD && flags.isMultiSelectEnabled) {
|
|
245
253
|
multiSelectDnD = (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || tr.selection.empty ? undefined : multiSelectDnD;
|
|
246
254
|
}
|
|
247
|
-
var _getTrMetadata = (0, _transactions.getTrMetadata)(tr),
|
|
248
|
-
from = _getTrMetadata.from,
|
|
249
|
-
to = _getTrMetadata.to,
|
|
250
|
-
numReplaceSteps = _getTrMetadata.numReplaceSteps,
|
|
251
|
-
isAllText = _getTrMetadata.isAllText;
|
|
252
255
|
var maybeNodeCountChanged = !isAllText && numReplaceSteps > 0;
|
|
253
256
|
var latestActiveNode;
|
|
254
257
|
if ((0, _platformFeatureFlags.fg)('platform_editor_remove_drag_handle_fix')) {
|
|
255
258
|
latestActiveNode = meta === null || meta === void 0 ? void 0 : meta.activeNode;
|
|
256
|
-
if (!latestActiveNode && !isActiveNodeDeleted) {
|
|
259
|
+
if (!latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
257
260
|
latestActiveNode = activeNode;
|
|
258
261
|
}
|
|
259
262
|
} else {
|
|
@@ -271,8 +274,8 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
271
274
|
decorations = decorations.remove(oldNodeDecs);
|
|
272
275
|
var newNodeDecs = (0, _decorationsAnchor.nodeDecorations)(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
|
|
273
276
|
decorations = decorations.add(newState.doc, newNodeDecs);
|
|
274
|
-
if (
|
|
275
|
-
if (
|
|
277
|
+
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
|
|
278
|
+
if (latestActiveNode && !isActiveNodeDeleted) {
|
|
276
279
|
// Find the newly minted node decs that touch the active node
|
|
277
280
|
var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, latestActiveNode.pos - 1, to);
|
|
278
281
|
|
|
@@ -290,7 +293,10 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
290
293
|
latestActiveNode.anchorName = nodeDecAtActivePos.spec.anchorName;
|
|
291
294
|
latestActiveNode.nodeType = nodeDecAtActivePos.spec.nodeType;
|
|
292
295
|
}
|
|
293
|
-
}
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
// active node may have been deleted or replaced with another of the same size, if replaced go ahead and remap the active node
|
|
299
|
+
if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
294
300
|
var _nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
|
|
295
301
|
var rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
|
|
296
302
|
if (_nodeDecAtActivePos || rootNodeDecAtActivePos) {
|
|
@@ -326,7 +332,7 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
326
332
|
var shouldRemoveHandle = false;
|
|
327
333
|
if ((0, _platformFeatureFlags.fg)('platform_editor_remove_drag_handle_fix')) {
|
|
328
334
|
// If the active node is missing, we need to remove the handle
|
|
329
|
-
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
335
|
+
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted && !isReplacedWithSameSize || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
330
336
|
} else {
|
|
331
337
|
// Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
|
|
332
338
|
shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
|
|
@@ -336,21 +342,22 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
336
342
|
var oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
|
|
337
343
|
decorations = decorations.remove(oldHandle);
|
|
338
344
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
339
|
-
var
|
|
345
|
+
var _activeNode7, _activeNode8;
|
|
346
|
+
var oldQuickInsertButton = (0, _decorationsQuickInsertButton.findQuickInsertInsertButtonDecoration)(decorations, (_activeNode7 = activeNode) === null || _activeNode7 === void 0 ? void 0 : _activeNode7.rootPos, (_activeNode8 = activeNode) === null || _activeNode8 === void 0 ? void 0 : _activeNode8.rootPos);
|
|
340
347
|
decorations = decorations.remove(oldQuickInsertButton);
|
|
341
348
|
}
|
|
342
349
|
} else if (api) {
|
|
343
350
|
var _latestActiveNode5;
|
|
344
351
|
if (shouldRecreateHandle) {
|
|
345
|
-
var
|
|
346
|
-
var _oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (
|
|
352
|
+
var _activeNode9, _activeNode10, _latestActiveNode, _latestActiveNode2, _latestActiveNode3, _latestActiveNode4;
|
|
353
|
+
var _oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.pos, (_activeNode10 = activeNode) === null || _activeNode10 === void 0 ? void 0 : _activeNode10.pos);
|
|
347
354
|
decorations = decorations.remove(_oldHandle);
|
|
348
355
|
var handleDec = (0, _decorationsDragHandle.dragHandleDecoration)(api, formatMessage, (_latestActiveNode = latestActiveNode) === null || _latestActiveNode === void 0 ? void 0 : _latestActiveNode.pos, (_latestActiveNode2 = latestActiveNode) === null || _latestActiveNode2 === void 0 ? void 0 : _latestActiveNode2.anchorName, (_latestActiveNode3 = latestActiveNode) === null || _latestActiveNode3 === void 0 ? void 0 : _latestActiveNode3.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode4 = latestActiveNode) === null || _latestActiveNode4 === void 0 ? void 0 : _latestActiveNode4.handleOptions);
|
|
349
356
|
decorations = decorations.add(newState.doc, [handleDec]);
|
|
350
357
|
}
|
|
351
358
|
if (shouldRecreateQuickInsertButton && ((_latestActiveNode5 = latestActiveNode) === null || _latestActiveNode5 === void 0 ? void 0 : _latestActiveNode5.rootPos) !== undefined && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
352
|
-
var
|
|
353
|
-
var _oldQuickInsertButton = (0, _decorationsQuickInsertButton.findQuickInsertInsertButtonDecoration)(decorations, (
|
|
359
|
+
var _activeNode11, _activeNode12, _latestActiveNode6, _latestActiveNode7, _latestActiveNode8, _latestActiveNode9, _latestActiveNode10;
|
|
360
|
+
var _oldQuickInsertButton = (0, _decorationsQuickInsertButton.findQuickInsertInsertButtonDecoration)(decorations, (_activeNode11 = activeNode) === null || _activeNode11 === void 0 ? void 0 : _activeNode11.rootPos, (_activeNode12 = activeNode) === null || _activeNode12 === void 0 ? void 0 : _activeNode12.rootPos);
|
|
354
361
|
decorations = decorations.remove(_oldQuickInsertButton);
|
|
355
362
|
var quickInsertButton = (0, _decorationsQuickInsertButton.quickInsertButtonDecoration)(api, formatMessage, (_latestActiveNode6 = latestActiveNode) === null || _latestActiveNode6 === void 0 ? void 0 : _latestActiveNode6.rootPos, (_latestActiveNode7 = latestActiveNode) === null || _latestActiveNode7 === void 0 ? void 0 : _latestActiveNode7.anchorName, (_latestActiveNode8 = latestActiveNode) === null || _latestActiveNode8 === void 0 ? void 0 : _latestActiveNode8.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode9 = latestActiveNode) === null || _latestActiveNode9 === void 0 ? void 0 : _latestActiveNode9.rootAnchorName, (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.rootNodeType);
|
|
356
363
|
decorations = decorations.add(newState.doc, [quickInsertButton]);
|
|
@@ -380,7 +387,15 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
380
387
|
decorations = decorations.add(newState.doc, [(0, _decorationsDragHandle.emptyParagraphNodeDecorations)()]);
|
|
381
388
|
}
|
|
382
389
|
}
|
|
383
|
-
var newActiveNode
|
|
390
|
+
var newActiveNode;
|
|
391
|
+
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
392
|
+
var _latestActiveNode11, _latestActiveNode12;
|
|
393
|
+
// remove isEmptyDoc check and let decorations render and determine their own visibility
|
|
394
|
+
newActiveNode = !(meta !== null && meta !== void 0 && meta.activeNode) && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.pos, (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.pos).length === 0 ? null : latestActiveNode;
|
|
395
|
+
} else {
|
|
396
|
+
var _latestActiveNode13, _latestActiveNode14;
|
|
397
|
+
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
398
|
+
}
|
|
384
399
|
var isMenuOpenNew = isMenuOpen;
|
|
385
400
|
if (_consts.BLOCK_MENU_ENABLED && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
386
401
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isStepText = exports.isStepDelete = exports.getTrMetadata = void 0;
|
|
7
7
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
8
9
|
/**
|
|
9
10
|
* Checks if step adds inline char
|
|
10
11
|
* @param s
|
|
@@ -25,6 +26,20 @@ var isStepDelete = exports.isStepDelete = function isStepDelete(s) {
|
|
|
25
26
|
return s.to === s.from + 1 && content.size === 0;
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Check if content being replaced is replaced with another of the same size
|
|
31
|
+
* This can occur on empty docs and 'backspace' is pressed, the paragraph node is re-drawn
|
|
32
|
+
* @param s
|
|
33
|
+
* @returns True if content being replaced is replaced with another of the same size
|
|
34
|
+
*/
|
|
35
|
+
var isStepContentReplacedWithAnotherOfSameSize = function isStepContentReplacedWithAnotherOfSameSize(s) {
|
|
36
|
+
if (s instanceof _transform.ReplaceAroundStep) {
|
|
37
|
+
var replacedContentSize = s.to - s.from;
|
|
38
|
+
return s.slice.content.size === replacedContentSize;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
|
|
28
43
|
/**
|
|
29
44
|
* Get metadata from the transaction.
|
|
30
45
|
* @param tr
|
|
@@ -37,11 +52,15 @@ var getTrMetadata = exports.getTrMetadata = function getTrMetadata(tr) {
|
|
|
37
52
|
var to;
|
|
38
53
|
var numReplaceSteps = 0;
|
|
39
54
|
var isAllText = true;
|
|
55
|
+
var isReplacedWithSameSize = false;
|
|
40
56
|
tr.steps.forEach(function (s) {
|
|
41
57
|
if (s instanceof _transform.ReplaceStep || s instanceof _transform.ReplaceAroundStep) {
|
|
42
58
|
if (s instanceof _transform.ReplaceAroundStep || s instanceof _transform.ReplaceStep && !isStepText(s) && !isStepDelete(s)) {
|
|
43
59
|
isAllText = false;
|
|
44
60
|
}
|
|
61
|
+
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
62
|
+
isReplacedWithSameSize = isStepContentReplacedWithAnotherOfSameSize(s);
|
|
63
|
+
}
|
|
45
64
|
var mappedTo = tr.mapping.map(s.to);
|
|
46
65
|
var $to = s.from + s.slice.size;
|
|
47
66
|
$to = $to > mappedTo ? $to : mappedTo;
|
|
@@ -60,6 +79,7 @@ var getTrMetadata = exports.getTrMetadata = function getTrMetadata(tr) {
|
|
|
60
79
|
from: from,
|
|
61
80
|
to: to,
|
|
62
81
|
numReplaceSteps: numReplaceSteps,
|
|
63
|
-
isAllText: isAllText
|
|
82
|
+
isAllText: isAllText,
|
|
83
|
+
isReplacedWithSameSize: isReplacedWithSameSize
|
|
64
84
|
};
|
|
65
85
|
};
|
|
@@ -20,6 +20,7 @@ var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-
|
|
|
20
20
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
21
21
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
22
22
|
var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-handler"));
|
|
23
|
+
var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/utility/drag-handle-vertical"));
|
|
23
24
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
24
25
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
25
26
|
var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview");
|
|
@@ -661,9 +662,11 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
|
|
|
661
662
|
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
662
663
|
,
|
|
663
664
|
onDragStart: handleIconDragStart
|
|
664
|
-
}, (0, _react2.jsx)(
|
|
665
|
+
}, (0, _react2.jsx)(_dragHandleVertical.default, {
|
|
666
|
+
spacing: "spacious",
|
|
665
667
|
label: "",
|
|
666
|
-
|
|
668
|
+
LEGACY_fallbackIcon: _dragHandler.default,
|
|
669
|
+
LEGACY_size: "medium"
|
|
667
670
|
})))
|
|
668
671
|
);
|
|
669
672
|
};
|
|
@@ -181,7 +181,7 @@ const getDecorationAtPos = (decorations, pos, to) => {
|
|
|
181
181
|
return nodeDecAtActivePos;
|
|
182
182
|
};
|
|
183
183
|
export const newApply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache) => {
|
|
184
|
-
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging,
|
|
184
|
+
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging, _meta$isDragging2, _meta$toggleMenu, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
|
|
185
185
|
let {
|
|
186
186
|
activeNode,
|
|
187
187
|
decorations,
|
|
@@ -200,14 +200,21 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
200
200
|
lastDragCancelled
|
|
201
201
|
} = currentState;
|
|
202
202
|
let isActiveNodeDeleted = false;
|
|
203
|
+
const {
|
|
204
|
+
from,
|
|
205
|
+
to,
|
|
206
|
+
numReplaceSteps,
|
|
207
|
+
isAllText,
|
|
208
|
+
isReplacedWithSameSize
|
|
209
|
+
} = getTrMetadata(tr);
|
|
203
210
|
|
|
204
211
|
// When steps exist, remap existing decorations, activeNode and multi select positions
|
|
205
212
|
if (tr.docChanged) {
|
|
206
213
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
207
214
|
if (activeNode) {
|
|
208
|
-
const mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
209
|
-
isActiveNodeDeleted = mappedPos.deleted;
|
|
210
215
|
if (editorExperiment('platform_editor_controls', 'control')) {
|
|
216
|
+
const mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
217
|
+
isActiveNodeDeleted = mappedPos.deleted;
|
|
211
218
|
activeNode = {
|
|
212
219
|
pos: mappedPos.pos,
|
|
213
220
|
anchorName: activeNode.anchorName,
|
|
@@ -215,10 +222,12 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
215
222
|
};
|
|
216
223
|
} else {
|
|
217
224
|
var _mappedRootPos$pos, _mappedRootPos;
|
|
225
|
+
const mappedPos = tr.mapping.mapResult(activeNode.pos, -1);
|
|
226
|
+
isActiveNodeDeleted = mappedPos.deletedAfter;
|
|
218
227
|
// for editor controls, remap the rootPos as well
|
|
219
228
|
let mappedRootPos;
|
|
220
229
|
if (activeNode.rootPos !== undefined) {
|
|
221
|
-
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos);
|
|
230
|
+
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos, -1);
|
|
222
231
|
}
|
|
223
232
|
activeNode = {
|
|
224
233
|
pos: mappedPos.pos,
|
|
@@ -242,17 +251,11 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
242
251
|
if (multiSelectDnD && flags.isMultiSelectEnabled) {
|
|
243
252
|
multiSelectDnD = (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || tr.selection.empty ? undefined : multiSelectDnD;
|
|
244
253
|
}
|
|
245
|
-
const {
|
|
246
|
-
from,
|
|
247
|
-
to,
|
|
248
|
-
numReplaceSteps,
|
|
249
|
-
isAllText
|
|
250
|
-
} = getTrMetadata(tr);
|
|
251
254
|
const maybeNodeCountChanged = !isAllText && numReplaceSteps > 0;
|
|
252
255
|
let latestActiveNode;
|
|
253
256
|
if (fg('platform_editor_remove_drag_handle_fix')) {
|
|
254
257
|
latestActiveNode = meta === null || meta === void 0 ? void 0 : meta.activeNode;
|
|
255
|
-
if (!latestActiveNode && !isActiveNodeDeleted) {
|
|
258
|
+
if (!latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
256
259
|
latestActiveNode = activeNode;
|
|
257
260
|
}
|
|
258
261
|
} else {
|
|
@@ -270,8 +273,8 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
270
273
|
decorations = decorations.remove(oldNodeDecs);
|
|
271
274
|
const newNodeDecs = nodeDecorations(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
|
|
272
275
|
decorations = decorations.add(newState.doc, newNodeDecs);
|
|
273
|
-
if (
|
|
274
|
-
if (
|
|
276
|
+
if (editorExperiment('platform_editor_controls', 'control')) {
|
|
277
|
+
if (latestActiveNode && !isActiveNodeDeleted) {
|
|
275
278
|
// Find the newly minted node decs that touch the active node
|
|
276
279
|
const findNewNodeDecs = findNodeDecs(decorations, latestActiveNode.pos - 1, to);
|
|
277
280
|
|
|
@@ -287,7 +290,10 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
287
290
|
latestActiveNode.anchorName = nodeDecAtActivePos.spec.anchorName;
|
|
288
291
|
latestActiveNode.nodeType = nodeDecAtActivePos.spec.nodeType;
|
|
289
292
|
}
|
|
290
|
-
}
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
// active node may have been deleted or replaced with another of the same size, if replaced go ahead and remap the active node
|
|
296
|
+
if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
291
297
|
const nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
|
|
292
298
|
const rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
|
|
293
299
|
if (nodeDecAtActivePos || rootNodeDecAtActivePos) {
|
|
@@ -323,7 +329,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
323
329
|
let shouldRemoveHandle = false;
|
|
324
330
|
if (fg('platform_editor_remove_drag_handle_fix')) {
|
|
325
331
|
// If the active node is missing, we need to remove the handle
|
|
326
|
-
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
332
|
+
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted && !isReplacedWithSameSize || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
327
333
|
} else {
|
|
328
334
|
// Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
|
|
329
335
|
shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
|
|
@@ -333,21 +339,22 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
333
339
|
const oldHandle = findHandleDec(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
|
|
334
340
|
decorations = decorations.remove(oldHandle);
|
|
335
341
|
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
336
|
-
|
|
342
|
+
var _activeNode7, _activeNode8;
|
|
343
|
+
const oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode7 = activeNode) === null || _activeNode7 === void 0 ? void 0 : _activeNode7.rootPos, (_activeNode8 = activeNode) === null || _activeNode8 === void 0 ? void 0 : _activeNode8.rootPos);
|
|
337
344
|
decorations = decorations.remove(oldQuickInsertButton);
|
|
338
345
|
}
|
|
339
346
|
} else if (api) {
|
|
340
347
|
var _latestActiveNode5;
|
|
341
348
|
if (shouldRecreateHandle) {
|
|
342
|
-
var
|
|
343
|
-
const oldHandle = findHandleDec(decorations, (
|
|
349
|
+
var _activeNode9, _activeNode10, _latestActiveNode, _latestActiveNode2, _latestActiveNode3, _latestActiveNode4;
|
|
350
|
+
const oldHandle = findHandleDec(decorations, (_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.pos, (_activeNode10 = activeNode) === null || _activeNode10 === void 0 ? void 0 : _activeNode10.pos);
|
|
344
351
|
decorations = decorations.remove(oldHandle);
|
|
345
352
|
const handleDec = dragHandleDecoration(api, formatMessage, (_latestActiveNode = latestActiveNode) === null || _latestActiveNode === void 0 ? void 0 : _latestActiveNode.pos, (_latestActiveNode2 = latestActiveNode) === null || _latestActiveNode2 === void 0 ? void 0 : _latestActiveNode2.anchorName, (_latestActiveNode3 = latestActiveNode) === null || _latestActiveNode3 === void 0 ? void 0 : _latestActiveNode3.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode4 = latestActiveNode) === null || _latestActiveNode4 === void 0 ? void 0 : _latestActiveNode4.handleOptions);
|
|
346
353
|
decorations = decorations.add(newState.doc, [handleDec]);
|
|
347
354
|
}
|
|
348
355
|
if (shouldRecreateQuickInsertButton && ((_latestActiveNode5 = latestActiveNode) === null || _latestActiveNode5 === void 0 ? void 0 : _latestActiveNode5.rootPos) !== undefined && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
349
|
-
var
|
|
350
|
-
const oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (
|
|
356
|
+
var _activeNode11, _activeNode12, _latestActiveNode6, _latestActiveNode7, _latestActiveNode8, _latestActiveNode9, _latestActiveNode10;
|
|
357
|
+
const oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode11 = activeNode) === null || _activeNode11 === void 0 ? void 0 : _activeNode11.rootPos, (_activeNode12 = activeNode) === null || _activeNode12 === void 0 ? void 0 : _activeNode12.rootPos);
|
|
351
358
|
decorations = decorations.remove(oldQuickInsertButton);
|
|
352
359
|
const quickInsertButton = quickInsertButtonDecoration(api, formatMessage, (_latestActiveNode6 = latestActiveNode) === null || _latestActiveNode6 === void 0 ? void 0 : _latestActiveNode6.rootPos, (_latestActiveNode7 = latestActiveNode) === null || _latestActiveNode7 === void 0 ? void 0 : _latestActiveNode7.anchorName, (_latestActiveNode8 = latestActiveNode) === null || _latestActiveNode8 === void 0 ? void 0 : _latestActiveNode8.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode9 = latestActiveNode) === null || _latestActiveNode9 === void 0 ? void 0 : _latestActiveNode9.rootAnchorName, (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.rootNodeType);
|
|
353
360
|
decorations = decorations.add(newState.doc, [quickInsertButton]);
|
|
@@ -377,7 +384,15 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
|
|
|
377
384
|
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
378
385
|
}
|
|
379
386
|
}
|
|
380
|
-
|
|
387
|
+
let newActiveNode;
|
|
388
|
+
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
389
|
+
var _latestActiveNode11, _latestActiveNode12;
|
|
390
|
+
// remove isEmptyDoc check and let decorations render and determine their own visibility
|
|
391
|
+
newActiveNode = !(meta !== null && meta !== void 0 && meta.activeNode) && findHandleDec(decorations, (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.pos, (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.pos).length === 0 ? null : latestActiveNode;
|
|
392
|
+
} else {
|
|
393
|
+
var _latestActiveNode13, _latestActiveNode14;
|
|
394
|
+
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && findHandleDec(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
395
|
+
}
|
|
381
396
|
let isMenuOpenNew = isMenuOpen;
|
|
382
397
|
if (BLOCK_MENU_ENABLED && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
383
398
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if step adds inline char
|
|
4
5
|
* @param s
|
|
@@ -19,6 +20,20 @@ export const isStepDelete = s => {
|
|
|
19
20
|
return s.to === s.from + 1 && content.size === 0;
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Check if content being replaced is replaced with another of the same size
|
|
25
|
+
* This can occur on empty docs and 'backspace' is pressed, the paragraph node is re-drawn
|
|
26
|
+
* @param s
|
|
27
|
+
* @returns True if content being replaced is replaced with another of the same size
|
|
28
|
+
*/
|
|
29
|
+
const isStepContentReplacedWithAnotherOfSameSize = s => {
|
|
30
|
+
if (s instanceof ReplaceAroundStep) {
|
|
31
|
+
const replacedContentSize = s.to - s.from;
|
|
32
|
+
return s.slice.content.size === replacedContentSize;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
|
|
22
37
|
/**
|
|
23
38
|
* Get metadata from the transaction.
|
|
24
39
|
* @param tr
|
|
@@ -31,11 +46,15 @@ export const getTrMetadata = tr => {
|
|
|
31
46
|
let to;
|
|
32
47
|
let numReplaceSteps = 0;
|
|
33
48
|
let isAllText = true;
|
|
49
|
+
let isReplacedWithSameSize = false;
|
|
34
50
|
tr.steps.forEach(s => {
|
|
35
51
|
if (s instanceof ReplaceStep || s instanceof ReplaceAroundStep) {
|
|
36
52
|
if (s instanceof ReplaceAroundStep || s instanceof ReplaceStep && !isStepText(s) && !isStepDelete(s)) {
|
|
37
53
|
isAllText = false;
|
|
38
54
|
}
|
|
55
|
+
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
56
|
+
isReplacedWithSameSize = isStepContentReplacedWithAnotherOfSameSize(s);
|
|
57
|
+
}
|
|
39
58
|
const mappedTo = tr.mapping.map(s.to);
|
|
40
59
|
let $to = s.from + s.slice.size;
|
|
41
60
|
$to = $to > mappedTo ? $to : mappedTo;
|
|
@@ -54,6 +73,7 @@ export const getTrMetadata = tr => {
|
|
|
54
73
|
from,
|
|
55
74
|
to,
|
|
56
75
|
numReplaceSteps,
|
|
57
|
-
isAllText
|
|
76
|
+
isAllText,
|
|
77
|
+
isReplacedWithSameSize
|
|
58
78
|
};
|
|
59
79
|
};
|
|
@@ -17,6 +17,7 @@ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared
|
|
|
17
17
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
18
18
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
19
19
|
import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
20
|
+
import DragHandleVerticalIcon from '@atlaskit/icon/utility/drag-handle-vertical';
|
|
20
21
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
21
22
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
22
23
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
|
|
@@ -646,9 +647,11 @@ export const DragHandle = ({
|
|
|
646
647
|
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
647
648
|
,
|
|
648
649
|
onDragStart: handleIconDragStart
|
|
649
|
-
}, jsx(
|
|
650
|
+
}, jsx(DragHandleVerticalIcon, {
|
|
651
|
+
spacing: "spacious",
|
|
650
652
|
label: "",
|
|
651
|
-
|
|
653
|
+
LEGACY_fallbackIcon: DragHandlerIcon,
|
|
654
|
+
LEGACY_size: "medium"
|
|
652
655
|
})));
|
|
653
656
|
return !dragHandleDisabled && fg('platform_editor_element_drag_and_drop_ed_23873') ? jsx(Tooltip, {
|
|
654
657
|
content: jsx(TooltipContentWithMultipleShortcuts, {
|
|
@@ -180,7 +180,7 @@ var getDecorationAtPos = function getDecorationAtPos(decorations, pos, to) {
|
|
|
180
180
|
return nodeDecAtActivePos;
|
|
181
181
|
};
|
|
182
182
|
export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache) {
|
|
183
|
-
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging,
|
|
183
|
+
var _meta$multiSelectDnD, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging, _meta$isDragging2, _meta$toggleMenu, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging, _meta$isShiftDown, _meta$lastDragCancell;
|
|
184
184
|
var activeNode = currentState.activeNode,
|
|
185
185
|
decorations = currentState.decorations,
|
|
186
186
|
isResizerResizing = currentState.isResizerResizing,
|
|
@@ -195,14 +195,20 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
195
195
|
isShiftDown = currentState.isShiftDown,
|
|
196
196
|
lastDragCancelled = currentState.lastDragCancelled;
|
|
197
197
|
var isActiveNodeDeleted = false;
|
|
198
|
+
var _getTrMetadata = getTrMetadata(tr),
|
|
199
|
+
from = _getTrMetadata.from,
|
|
200
|
+
to = _getTrMetadata.to,
|
|
201
|
+
numReplaceSteps = _getTrMetadata.numReplaceSteps,
|
|
202
|
+
isAllText = _getTrMetadata.isAllText,
|
|
203
|
+
isReplacedWithSameSize = _getTrMetadata.isReplacedWithSameSize;
|
|
198
204
|
|
|
199
205
|
// When steps exist, remap existing decorations, activeNode and multi select positions
|
|
200
206
|
if (tr.docChanged) {
|
|
201
207
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
202
208
|
if (activeNode) {
|
|
203
|
-
var mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
204
|
-
isActiveNodeDeleted = mappedPos.deleted;
|
|
205
209
|
if (editorExperiment('platform_editor_controls', 'control')) {
|
|
210
|
+
var mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
211
|
+
isActiveNodeDeleted = mappedPos.deleted;
|
|
206
212
|
activeNode = {
|
|
207
213
|
pos: mappedPos.pos,
|
|
208
214
|
anchorName: activeNode.anchorName,
|
|
@@ -210,13 +216,15 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
210
216
|
};
|
|
211
217
|
} else {
|
|
212
218
|
var _mappedRootPos$pos, _mappedRootPos;
|
|
219
|
+
var _mappedPos = tr.mapping.mapResult(activeNode.pos, -1);
|
|
220
|
+
isActiveNodeDeleted = _mappedPos.deletedAfter;
|
|
213
221
|
// for editor controls, remap the rootPos as well
|
|
214
222
|
var mappedRootPos;
|
|
215
223
|
if (activeNode.rootPos !== undefined) {
|
|
216
|
-
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos);
|
|
224
|
+
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos, -1);
|
|
217
225
|
}
|
|
218
226
|
activeNode = {
|
|
219
|
-
pos:
|
|
227
|
+
pos: _mappedPos.pos,
|
|
220
228
|
anchorName: activeNode.anchorName,
|
|
221
229
|
nodeType: activeNode.nodeType,
|
|
222
230
|
rootPos: (_mappedRootPos$pos = (_mappedRootPos = mappedRootPos) === null || _mappedRootPos === void 0 ? void 0 : _mappedRootPos.pos) !== null && _mappedRootPos$pos !== void 0 ? _mappedRootPos$pos : activeNode.rootPos,
|
|
@@ -237,16 +245,11 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
237
245
|
if (multiSelectDnD && flags.isMultiSelectEnabled) {
|
|
238
246
|
multiSelectDnD = (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || tr.selection.empty ? undefined : multiSelectDnD;
|
|
239
247
|
}
|
|
240
|
-
var _getTrMetadata = getTrMetadata(tr),
|
|
241
|
-
from = _getTrMetadata.from,
|
|
242
|
-
to = _getTrMetadata.to,
|
|
243
|
-
numReplaceSteps = _getTrMetadata.numReplaceSteps,
|
|
244
|
-
isAllText = _getTrMetadata.isAllText;
|
|
245
248
|
var maybeNodeCountChanged = !isAllText && numReplaceSteps > 0;
|
|
246
249
|
var latestActiveNode;
|
|
247
250
|
if (fg('platform_editor_remove_drag_handle_fix')) {
|
|
248
251
|
latestActiveNode = meta === null || meta === void 0 ? void 0 : meta.activeNode;
|
|
249
|
-
if (!latestActiveNode && !isActiveNodeDeleted) {
|
|
252
|
+
if (!latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
250
253
|
latestActiveNode = activeNode;
|
|
251
254
|
}
|
|
252
255
|
} else {
|
|
@@ -264,8 +267,8 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
264
267
|
decorations = decorations.remove(oldNodeDecs);
|
|
265
268
|
var newNodeDecs = nodeDecorations(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
|
|
266
269
|
decorations = decorations.add(newState.doc, newNodeDecs);
|
|
267
|
-
if (
|
|
268
|
-
if (
|
|
270
|
+
if (editorExperiment('platform_editor_controls', 'control')) {
|
|
271
|
+
if (latestActiveNode && !isActiveNodeDeleted) {
|
|
269
272
|
// Find the newly minted node decs that touch the active node
|
|
270
273
|
var findNewNodeDecs = findNodeDecs(decorations, latestActiveNode.pos - 1, to);
|
|
271
274
|
|
|
@@ -283,7 +286,10 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
283
286
|
latestActiveNode.anchorName = nodeDecAtActivePos.spec.anchorName;
|
|
284
287
|
latestActiveNode.nodeType = nodeDecAtActivePos.spec.nodeType;
|
|
285
288
|
}
|
|
286
|
-
}
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
// active node may have been deleted or replaced with another of the same size, if replaced go ahead and remap the active node
|
|
292
|
+
if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
|
|
287
293
|
var _nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
|
|
288
294
|
var rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
|
|
289
295
|
if (_nodeDecAtActivePos || rootNodeDecAtActivePos) {
|
|
@@ -319,7 +325,7 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
319
325
|
var shouldRemoveHandle = false;
|
|
320
326
|
if (fg('platform_editor_remove_drag_handle_fix')) {
|
|
321
327
|
// If the active node is missing, we need to remove the handle
|
|
322
|
-
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
328
|
+
shouldRemoveHandle = latestActiveNode ? isResizerResizing || isActiveNodeDeleted && !isReplacedWithSameSize || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved) : true;
|
|
323
329
|
} else {
|
|
324
330
|
// Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
|
|
325
331
|
shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
|
|
@@ -329,21 +335,22 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
329
335
|
var oldHandle = findHandleDec(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
|
|
330
336
|
decorations = decorations.remove(oldHandle);
|
|
331
337
|
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
332
|
-
var
|
|
338
|
+
var _activeNode7, _activeNode8;
|
|
339
|
+
var oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode7 = activeNode) === null || _activeNode7 === void 0 ? void 0 : _activeNode7.rootPos, (_activeNode8 = activeNode) === null || _activeNode8 === void 0 ? void 0 : _activeNode8.rootPos);
|
|
333
340
|
decorations = decorations.remove(oldQuickInsertButton);
|
|
334
341
|
}
|
|
335
342
|
} else if (api) {
|
|
336
343
|
var _latestActiveNode5;
|
|
337
344
|
if (shouldRecreateHandle) {
|
|
338
|
-
var
|
|
339
|
-
var _oldHandle = findHandleDec(decorations, (
|
|
345
|
+
var _activeNode9, _activeNode10, _latestActiveNode, _latestActiveNode2, _latestActiveNode3, _latestActiveNode4;
|
|
346
|
+
var _oldHandle = findHandleDec(decorations, (_activeNode9 = activeNode) === null || _activeNode9 === void 0 ? void 0 : _activeNode9.pos, (_activeNode10 = activeNode) === null || _activeNode10 === void 0 ? void 0 : _activeNode10.pos);
|
|
340
347
|
decorations = decorations.remove(_oldHandle);
|
|
341
348
|
var handleDec = dragHandleDecoration(api, formatMessage, (_latestActiveNode = latestActiveNode) === null || _latestActiveNode === void 0 ? void 0 : _latestActiveNode.pos, (_latestActiveNode2 = latestActiveNode) === null || _latestActiveNode2 === void 0 ? void 0 : _latestActiveNode2.anchorName, (_latestActiveNode3 = latestActiveNode) === null || _latestActiveNode3 === void 0 ? void 0 : _latestActiveNode3.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode4 = latestActiveNode) === null || _latestActiveNode4 === void 0 ? void 0 : _latestActiveNode4.handleOptions);
|
|
342
349
|
decorations = decorations.add(newState.doc, [handleDec]);
|
|
343
350
|
}
|
|
344
351
|
if (shouldRecreateQuickInsertButton && ((_latestActiveNode5 = latestActiveNode) === null || _latestActiveNode5 === void 0 ? void 0 : _latestActiveNode5.rootPos) !== undefined && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
345
|
-
var
|
|
346
|
-
var _oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (
|
|
352
|
+
var _activeNode11, _activeNode12, _latestActiveNode6, _latestActiveNode7, _latestActiveNode8, _latestActiveNode9, _latestActiveNode10;
|
|
353
|
+
var _oldQuickInsertButton = findQuickInsertInsertButtonDecoration(decorations, (_activeNode11 = activeNode) === null || _activeNode11 === void 0 ? void 0 : _activeNode11.rootPos, (_activeNode12 = activeNode) === null || _activeNode12 === void 0 ? void 0 : _activeNode12.rootPos);
|
|
347
354
|
decorations = decorations.remove(_oldQuickInsertButton);
|
|
348
355
|
var quickInsertButton = quickInsertButtonDecoration(api, formatMessage, (_latestActiveNode6 = latestActiveNode) === null || _latestActiveNode6 === void 0 ? void 0 : _latestActiveNode6.rootPos, (_latestActiveNode7 = latestActiveNode) === null || _latestActiveNode7 === void 0 ? void 0 : _latestActiveNode7.anchorName, (_latestActiveNode8 = latestActiveNode) === null || _latestActiveNode8 === void 0 ? void 0 : _latestActiveNode8.nodeType, nodeViewPortalProviderAPI, (_latestActiveNode9 = latestActiveNode) === null || _latestActiveNode9 === void 0 ? void 0 : _latestActiveNode9.rootAnchorName, (_latestActiveNode10 = latestActiveNode) === null || _latestActiveNode10 === void 0 ? void 0 : _latestActiveNode10.rootNodeType);
|
|
349
356
|
decorations = decorations.add(newState.doc, [quickInsertButton]);
|
|
@@ -373,7 +380,15 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
373
380
|
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
374
381
|
}
|
|
375
382
|
}
|
|
376
|
-
var newActiveNode
|
|
383
|
+
var newActiveNode;
|
|
384
|
+
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
385
|
+
var _latestActiveNode11, _latestActiveNode12;
|
|
386
|
+
// remove isEmptyDoc check and let decorations render and determine their own visibility
|
|
387
|
+
newActiveNode = !(meta !== null && meta !== void 0 && meta.activeNode) && findHandleDec(decorations, (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.pos, (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.pos).length === 0 ? null : latestActiveNode;
|
|
388
|
+
} else {
|
|
389
|
+
var _latestActiveNode13, _latestActiveNode14;
|
|
390
|
+
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && findHandleDec(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
391
|
+
}
|
|
377
392
|
var isMenuOpenNew = isMenuOpen;
|
|
378
393
|
if (BLOCK_MENU_ENABLED && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
379
394
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if step adds inline char
|
|
4
5
|
* @param s
|
|
@@ -19,6 +20,20 @@ export var isStepDelete = function isStepDelete(s) {
|
|
|
19
20
|
return s.to === s.from + 1 && content.size === 0;
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Check if content being replaced is replaced with another of the same size
|
|
25
|
+
* This can occur on empty docs and 'backspace' is pressed, the paragraph node is re-drawn
|
|
26
|
+
* @param s
|
|
27
|
+
* @returns True if content being replaced is replaced with another of the same size
|
|
28
|
+
*/
|
|
29
|
+
var isStepContentReplacedWithAnotherOfSameSize = function isStepContentReplacedWithAnotherOfSameSize(s) {
|
|
30
|
+
if (s instanceof ReplaceAroundStep) {
|
|
31
|
+
var replacedContentSize = s.to - s.from;
|
|
32
|
+
return s.slice.content.size === replacedContentSize;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
|
|
22
37
|
/**
|
|
23
38
|
* Get metadata from the transaction.
|
|
24
39
|
* @param tr
|
|
@@ -31,11 +46,15 @@ export var getTrMetadata = function getTrMetadata(tr) {
|
|
|
31
46
|
var to;
|
|
32
47
|
var numReplaceSteps = 0;
|
|
33
48
|
var isAllText = true;
|
|
49
|
+
var isReplacedWithSameSize = false;
|
|
34
50
|
tr.steps.forEach(function (s) {
|
|
35
51
|
if (s instanceof ReplaceStep || s instanceof ReplaceAroundStep) {
|
|
36
52
|
if (s instanceof ReplaceAroundStep || s instanceof ReplaceStep && !isStepText(s) && !isStepDelete(s)) {
|
|
37
53
|
isAllText = false;
|
|
38
54
|
}
|
|
55
|
+
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
56
|
+
isReplacedWithSameSize = isStepContentReplacedWithAnotherOfSameSize(s);
|
|
57
|
+
}
|
|
39
58
|
var mappedTo = tr.mapping.map(s.to);
|
|
40
59
|
var $to = s.from + s.slice.size;
|
|
41
60
|
$to = $to > mappedTo ? $to : mappedTo;
|
|
@@ -54,6 +73,7 @@ export var getTrMetadata = function getTrMetadata(tr) {
|
|
|
54
73
|
from: from,
|
|
55
74
|
to: to,
|
|
56
75
|
numReplaceSteps: numReplaceSteps,
|
|
57
|
-
isAllText: isAllText
|
|
76
|
+
isAllText: isAllText,
|
|
77
|
+
isReplacedWithSameSize: isReplacedWithSameSize
|
|
58
78
|
};
|
|
59
79
|
};
|
|
@@ -22,6 +22,7 @@ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared
|
|
|
22
22
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
23
23
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
24
24
|
import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
|
|
25
|
+
import DragHandleVerticalIcon from '@atlaskit/icon/utility/drag-handle-vertical';
|
|
25
26
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
26
27
|
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
27
28
|
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
|
|
@@ -658,9 +659,11 @@ export var DragHandle = function DragHandle(_ref) {
|
|
|
658
659
|
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
659
660
|
,
|
|
660
661
|
onDragStart: handleIconDragStart
|
|
661
|
-
}, jsx(
|
|
662
|
+
}, jsx(DragHandleVerticalIcon, {
|
|
663
|
+
spacing: "spacious",
|
|
662
664
|
label: "",
|
|
663
|
-
|
|
665
|
+
LEGACY_fallbackIcon: DragHandlerIcon,
|
|
666
|
+
LEGACY_size: "medium"
|
|
664
667
|
})))
|
|
665
668
|
);
|
|
666
669
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/adf-schema": "^47.6.0",
|
|
36
|
-
"@atlaskit/editor-common": "^102.
|
|
36
|
+
"@atlaskit/editor-common": "^102.12.0",
|
|
37
37
|
"@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-analytics": "^2.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
|