@atlaskit/editor-plugin-block-controls 20.0.3 → 20.1.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 +25 -0
- package/dist/cjs/blockControlsPlugin.js +53 -17
- package/dist/cjs/editor-commands/show-drag-handle.js +17 -5
- package/dist/cjs/pm-plugins/decorations-anchor.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/cjs/pm-plugins/decorations-surface-anchor.js +72 -0
- package/dist/cjs/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/cjs/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/cjs/pm-plugins/handle-sparse-mouse-over.js +125 -0
- package/dist/cjs/pm-plugins/main.js +66 -54
- package/dist/cjs/pm-plugins/sparse-surfaces.js +49 -0
- package/dist/cjs/pm-plugins/utils/sparse-surface-candidates.js +419 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-mapping.js +108 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-state.js +53 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-view.js +134 -0
- package/dist/cjs/pm-plugins/utils/surface-viewport.js +223 -0
- package/dist/cjs/pm-plugins/utils/transactions.js +5 -0
- package/dist/cjs/ui/block-controls-left-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-right-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-surface-context.js +1 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +6 -7
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/cjs/ui/drag-handle.js +5 -3
- package/dist/cjs/ui/drop-target-layout.js +3 -2
- package/dist/cjs/ui/drop-target.js +3 -2
- package/dist/cjs/ui/global-styles.js +69 -27
- package/dist/cjs/ui/inline-drop-target.js +6 -5
- package/dist/cjs/ui/utils/anchor-name.js +2 -1
- package/dist/cjs/ui/utils/dom-attr-name.js +3 -2
- package/dist/cjs/ui/utils/get-surface-placement.js +2 -1
- package/dist/es2019/blockControlsPlugin.js +42 -8
- package/dist/es2019/editor-commands/show-drag-handle.js +14 -2
- package/dist/es2019/pm-plugins/decorations-anchor.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/es2019/pm-plugins/decorations-surface-anchor.js +56 -0
- package/dist/es2019/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/es2019/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/es2019/pm-plugins/handle-sparse-mouse-over.js +116 -0
- package/dist/es2019/pm-plugins/main.js +70 -54
- package/dist/es2019/pm-plugins/sparse-surfaces.js +37 -0
- package/dist/es2019/pm-plugins/utils/sparse-surface-candidates.js +305 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-mapping.js +78 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-state.js +39 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-view.js +121 -0
- package/dist/es2019/pm-plugins/utils/surface-viewport.js +192 -0
- package/dist/es2019/pm-plugins/utils/transactions.js +5 -0
- package/dist/es2019/ui/block-controls-left-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-right-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-surface-context.js +1 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +4 -5
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/es2019/ui/drag-handle.js +5 -3
- package/dist/es2019/ui/drop-target-layout.js +3 -2
- package/dist/es2019/ui/drop-target.js +3 -2
- package/dist/es2019/ui/global-styles.js +67 -28
- package/dist/es2019/ui/inline-drop-target.js +6 -5
- package/dist/es2019/ui/utils/anchor-name.js +2 -1
- package/dist/es2019/ui/utils/dom-attr-name.js +3 -2
- package/dist/es2019/ui/utils/get-surface-placement.js +2 -1
- package/dist/esm/blockControlsPlugin.js +53 -17
- package/dist/esm/editor-commands/show-drag-handle.js +17 -5
- package/dist/esm/pm-plugins/decorations-anchor.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/esm/pm-plugins/decorations-surface-anchor.js +65 -0
- package/dist/esm/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/esm/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/esm/pm-plugins/handle-sparse-mouse-over.js +119 -0
- package/dist/esm/pm-plugins/main.js +66 -54
- package/dist/esm/pm-plugins/sparse-surfaces.js +43 -0
- package/dist/esm/pm-plugins/utils/sparse-surface-candidates.js +413 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-mapping.js +101 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-state.js +46 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-view.js +127 -0
- package/dist/esm/pm-plugins/utils/surface-viewport.js +217 -0
- package/dist/esm/pm-plugins/utils/transactions.js +5 -0
- package/dist/esm/ui/block-controls-left-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-right-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-surface-context.js +1 -0
- package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +7 -8
- package/dist/esm/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/esm/ui/drag-handle.js +5 -3
- package/dist/esm/ui/drop-target-layout.js +3 -2
- package/dist/esm/ui/drop-target.js +3 -2
- package/dist/esm/ui/global-styles.js +70 -28
- package/dist/esm/ui/inline-drop-target.js +6 -5
- package/dist/esm/ui/utils/anchor-name.js +2 -1
- package/dist/esm/ui/utils/dom-attr-name.js +3 -2
- package/dist/esm/ui/utils/get-surface-placement.js +2 -1
- package/dist/types/blockControlsPluginType.d.ts +10 -3
- package/dist/types/pm-plugins/decorations-surface-anchor.d.ts +22 -0
- package/dist/types/pm-plugins/handle-sparse-mouse-over.d.ts +5 -0
- package/dist/types/pm-plugins/main.d.ts +2 -9
- package/dist/types/pm-plugins/sparse-surfaces.d.ts +8 -0
- package/dist/types/pm-plugins/utils/sparse-surface-candidates.d.ts +89 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-mapping.d.ts +20 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-state.d.ts +27 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-view.d.ts +15 -0
- package/dist/types/pm-plugins/utils/surface-viewport.d.ts +10 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +3 -2
- package/package.json +6 -6
- package/dist/cjs/pm-plugins/utils/surface-node-positions.js +0 -100
- package/dist/es2019/pm-plugins/utils/surface-node-positions.js +0 -78
- package/dist/esm/pm-plugins/utils/surface-node-positions.js +0 -93
- package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +0 -14
|
@@ -9,7 +9,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
10
10
|
var _browserApis = require("@atlaskit/browser-apis");
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
-
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
13
12
|
var _browser = require("@atlaskit/editor-common/browser");
|
|
14
13
|
var _nodeAnchor = require("@atlaskit/editor-common/node-anchor");
|
|
15
14
|
var _performanceMeasures = require("@atlaskit/editor-common/performance-measures");
|
|
@@ -20,7 +19,6 @@ var _ui = require("@atlaskit/editor-common/ui");
|
|
|
20
19
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
21
20
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
22
21
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
23
|
-
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
24
22
|
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
25
23
|
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
26
24
|
var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
|
|
@@ -32,19 +30,20 @@ var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equa
|
|
|
32
30
|
var _consts = require("../ui/consts");
|
|
33
31
|
var _domAttrName = require("../ui/utils/dom-attr-name");
|
|
34
32
|
var _decorationsAnchor = require("./decorations-anchor");
|
|
33
|
+
var _decorationsCommon = require("./decorations-common");
|
|
35
34
|
var _decorationsDragHandle = require("./decorations-drag-handle");
|
|
36
35
|
var _decorationsDropTarget = require("./decorations-drop-target");
|
|
37
36
|
var _decorationsDropTargetActive = require("./decorations-drop-target-active");
|
|
38
37
|
var _decorationsQuickInsertButton = require("./decorations-quick-insert-button");
|
|
39
38
|
var _handleMouseDown = require("./handle-mouse-down");
|
|
40
39
|
var _handleMouseOver = require("./handle-mouse-over");
|
|
40
|
+
var _handleSparseMouseOver = require("./handle-sparse-mouse-over");
|
|
41
41
|
var _keymap = require("./keymap");
|
|
42
42
|
var _activeAnchorTracker = require("./utils/active-anchor-tracker");
|
|
43
43
|
var _analytics2 = require("./utils/analytics");
|
|
44
44
|
var _anchorUtils = require("./utils/anchor-utils");
|
|
45
45
|
var _getSelection = require("./utils/getSelection");
|
|
46
46
|
var _selection = require("./utils/selection");
|
|
47
|
-
var _surfaceNodePositions = require("./utils/surface-node-positions");
|
|
48
47
|
var _transactions = require("./utils/transactions");
|
|
49
48
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
50
49
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -242,20 +241,18 @@ var getDecorationAtPos = function getDecorationAtPos(state, decorations, pos, to
|
|
|
242
241
|
return nodeDecAtActivePos;
|
|
243
242
|
};
|
|
244
243
|
var _apply = exports.apply = function apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
245
|
-
var _meta$multiSelectDnD, _api$editorViewMode, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging2, _meta$
|
|
244
|
+
var _meta$multiSelectDnD, _api$editorViewMode, _activeNode, _activeNode2, _meta$activeNode$hand, _activeNode3, _activeNode4, _meta$isDragging2, _meta$toggleMenu, _meta$isDragging3, _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;
|
|
246
245
|
var rightSideControlsEnabled = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
247
246
|
var quickInsertButtonEnabled = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : true;
|
|
248
247
|
var anchorRectCache = arguments.length > 10 ? arguments[10] : undefined;
|
|
249
248
|
var resizeObserverWidth = arguments.length > 11 ? arguments[11] : undefined;
|
|
250
249
|
var pragmaticCleanup = arguments.length > 12 ? arguments[12] : undefined;
|
|
251
|
-
var
|
|
252
|
-
var limitedModeTeardown = arguments.length > 14 ? arguments[14] : undefined;
|
|
250
|
+
var limitedModeTeardown = arguments.length > 13 ? arguments[13] : undefined;
|
|
253
251
|
var activeNode = currentState.activeNode,
|
|
254
252
|
decorations = currentState.decorations,
|
|
255
253
|
isResizerResizing = currentState.isResizerResizing,
|
|
256
|
-
multiSelectDnD = currentState.multiSelectDnD
|
|
257
|
-
|
|
258
|
-
var previousActiveNode = activeNode;
|
|
254
|
+
multiSelectDnD = currentState.multiSelectDnD;
|
|
255
|
+
var surfaceNodePositions = currentState.surfaceNodePositions;
|
|
259
256
|
var editorHeight = currentState.editorHeight,
|
|
260
257
|
editorWidthLeft = currentState.editorWidthLeft,
|
|
261
258
|
editorWidthRight = currentState.editorWidthRight,
|
|
@@ -400,13 +397,28 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
400
397
|
if (activeNode.rootPos !== undefined) {
|
|
401
398
|
mappedRootPos = tr.mapping.mapResult(activeNode.rootPos, -1);
|
|
402
399
|
}
|
|
400
|
+
var mappedNodeType = activeNode.nodeType;
|
|
401
|
+
var mappedRootNodeType = activeNode.rootNodeType;
|
|
402
|
+
// Sparse mode does not redraw the old decorations. A block-type transaction may report
|
|
403
|
+
// a text range that excludes the active block position, so always refresh the already
|
|
404
|
+
// active node and root from the new document (for example, paragraph → heading-1).
|
|
405
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) {
|
|
406
|
+
var mappedNode = newState.doc.nodeAt(_mappedPos.pos);
|
|
407
|
+
if (mappedNode !== null && mappedNode !== void 0 && mappedNode.isBlock) {
|
|
408
|
+
mappedNodeType = (0, _decorationsCommon.getNodeTypeWithLevel)(mappedNode);
|
|
409
|
+
}
|
|
410
|
+
var mappedRootNode = mappedRootPos ? mappedRootPos.pos === _mappedPos.pos && mappedNode ? mappedNode : newState.doc.nodeAt(mappedRootPos.pos) : undefined;
|
|
411
|
+
if (mappedRootNode !== null && mappedRootNode !== void 0 && mappedRootNode.isBlock) {
|
|
412
|
+
mappedRootNodeType = (0, _decorationsCommon.getNodeTypeWithLevel)(mappedRootNode);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
403
415
|
activeNode = {
|
|
404
416
|
pos: _mappedPos.pos,
|
|
405
417
|
anchorName: activeNode.anchorName,
|
|
406
|
-
nodeType:
|
|
418
|
+
nodeType: mappedNodeType,
|
|
407
419
|
rootPos: (_mappedRootPos$pos = (_mappedRootPos = mappedRootPos) === null || _mappedRootPos === void 0 ? void 0 : _mappedRootPos.pos) !== null && _mappedRootPos$pos !== void 0 ? _mappedRootPos$pos : activeNode.rootPos,
|
|
408
420
|
rootAnchorName: activeNode.rootAnchorName,
|
|
409
|
-
rootNodeType:
|
|
421
|
+
rootNodeType: mappedRootNodeType
|
|
410
422
|
};
|
|
411
423
|
}
|
|
412
424
|
}
|
|
@@ -442,7 +454,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
442
454
|
var isNodeDecsMissing = isDecSetEmpty || maybeNodeCountChanged || (0, _editorExperiment.editorExperiment)('platform_editor_breakout_resizing', true) && hasJustFinishedResizing;
|
|
443
455
|
var shouldRedrawNodeDecs = !isResizerResizing && (isNodeDecsMissing || (meta === null || meta === void 0 ? void 0 : meta.isDragging)) &&
|
|
444
456
|
// Skip expensive anchor node decoration recalculations when native anchor support is enabled
|
|
445
|
-
!(0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true);
|
|
457
|
+
!((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) || (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration'));
|
|
446
458
|
var isActiveNodeModified = false;
|
|
447
459
|
if (api && shouldRedrawNodeDecs) {
|
|
448
460
|
var oldNodeDecs = (0, _decorationsAnchor.findNodeDecs)(newState, decorations, from, to);
|
|
@@ -518,14 +530,14 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
518
530
|
// In view mode with right-side controls, remove any lingering drag handle decorations
|
|
519
531
|
// (they may carry over from edit mode). Only remove drag handles specifically, not
|
|
520
532
|
// the remix button decorations (those are managed separately via showInViewMode).
|
|
521
|
-
if (
|
|
533
|
+
if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && isViewMode && rightSideControlsEnabled) {
|
|
522
534
|
var allHandleDecs = (0, _decorationsDragHandle.findHandleDec)(decorations, 0, newState.doc.content.size);
|
|
523
535
|
if (allHandleDecs.length > 0) {
|
|
524
536
|
decorations = decorations.remove(allHandleDecs);
|
|
525
537
|
}
|
|
526
538
|
}
|
|
527
539
|
if (shouldRemoveHandle) {
|
|
528
|
-
if (
|
|
540
|
+
if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) {
|
|
529
541
|
var _activeNode5, _activeNode6;
|
|
530
542
|
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);
|
|
531
543
|
decorations = decorations.remove(oldHandle);
|
|
@@ -537,7 +549,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
537
549
|
// after a doc change (e.g. pressing Enter splits a node), DecorationSet.map() can shift the
|
|
538
550
|
// decoration to a different position, so a point-range search would miss it and leave a stale
|
|
539
551
|
// attribute on the wrong DOM node.
|
|
540
|
-
if ((
|
|
552
|
+
if ((!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') || nodeDecorationRegistry.length > 0) && (0, _expValEquals.expValEquals)('platform_editor_controls_reliable_anchor', 'isEnabled', true)) {
|
|
541
553
|
var oldActiveNodeDec = (0, _decorationsDragHandle.findActiveDragHandleNodeDec)(decorations, 0, newState.doc.content.size);
|
|
542
554
|
decorations = decorations.remove(oldActiveNodeDec);
|
|
543
555
|
var oldActiveQuickInsertDec = (0, _decorationsQuickInsertButton.findActiveQuickInsertNodeDec)(decorations, 0, newState.doc.content.size);
|
|
@@ -599,7 +611,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
599
611
|
} else if (api) {
|
|
600
612
|
var _latestActiveNode5, _latestActiveNode10;
|
|
601
613
|
// The registry surface replaces the legacy drag-handle decorations during migration.
|
|
602
|
-
if (
|
|
614
|
+
if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && shouldRecreateHandle && (!rightSideControlsEnabled || !isViewMode)) {
|
|
603
615
|
var _activeNode11, _activeNode12, _latestActiveNode, _latestActiveNode2, _latestActiveNode3, _latestActiveNode4;
|
|
604
616
|
var _oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode11 = activeNode) === null || _activeNode11 === void 0 ? void 0 : _activeNode11.pos, (_activeNode12 = activeNode) === null || _activeNode12 === void 0 ? void 0 : _activeNode12.pos);
|
|
605
617
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -616,7 +628,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
616
628
|
});
|
|
617
629
|
decorations = decorations.add(newState.doc, [handleDec]);
|
|
618
630
|
}
|
|
619
|
-
if ((
|
|
631
|
+
if ((!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') ||
|
|
620
632
|
// nodeDecorationRegistry consumers (e.g. the legacy Remix button) rely
|
|
621
633
|
// on that same anchor-name for their own CSS anchor() positioning, so this must still run
|
|
622
634
|
// when such a consumer exists even if the legacy drag handle itself is disabled.
|
|
@@ -888,7 +900,10 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
888
900
|
}
|
|
889
901
|
}
|
|
890
902
|
var isEmptyDoc = (0, _utils.isEmptyDocument)(newState.doc);
|
|
891
|
-
if (
|
|
903
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && (meta === null || meta === void 0 ? void 0 : meta.isDragging) === false) {
|
|
904
|
+
decorations = decorations.remove((0, _decorationsAnchor.findNodeDecs)(newState, decorations));
|
|
905
|
+
}
|
|
906
|
+
if (isEmptyDoc && !((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) || (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration'))) {
|
|
892
907
|
var hasNodeDecoration = !!(0, _decorationsAnchor.findNodeDecs)(newState, decorations).length;
|
|
893
908
|
if (!hasNodeDecoration) {
|
|
894
909
|
decorations = decorations.add(newState.doc, [(0, _decorationsDragHandle.emptyParagraphNodeDecorations)()]);
|
|
@@ -901,27 +916,30 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
901
916
|
// remove isEmptyDoc check and let decorations render and determine their own visibility
|
|
902
917
|
// In view mode with right-side controls we render node decorations (right-edge button), not the
|
|
903
918
|
// handle - so findHandleDec is always empty. Don't clear activeNode in that case.
|
|
904
|
-
var hasHandleOrViewModeControls =
|
|
919
|
+
var hasHandleOrViewModeControls = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') || isViewMode && rightSideControlsEnabled || (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;
|
|
905
920
|
// Keep the registry surface mounted while its Block Menu owns focus.
|
|
906
|
-
var keepActiveNodeForOpenBlockMenu =
|
|
921
|
+
var keepActiveNodeForOpenBlockMenu = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && isMenuOpen;
|
|
907
922
|
newActiveNode = meta !== null && meta !== void 0 && meta.editorBlurred && !keepActiveNodeForOpenBlockMenu || !(meta !== null && meta !== void 0 && meta.activeNode) && !hasHandleOrViewModeControls ? null : latestActiveNode;
|
|
908
923
|
} else {
|
|
909
924
|
var _latestActiveNode13, _latestActiveNode14;
|
|
910
|
-
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) &&
|
|
911
|
-
}
|
|
912
|
-
if (flags.surfaceNodePositionsEnabled && resolvedSurfaces.length > 0) {
|
|
913
|
-
surfaceNodePositions = (0, _surfaceNodePositions.updateSurfaceNodePositions)({
|
|
914
|
-
activeNode: newActiveNode,
|
|
915
|
-
currentPositions: surfaceNodePositions,
|
|
916
|
-
from: from,
|
|
917
|
-
newState: newState,
|
|
918
|
-
previousActiveNode: previousActiveNode,
|
|
919
|
-
resolvedSurfaces: resolvedSurfaces,
|
|
920
|
-
to: to,
|
|
921
|
-
tr: tr
|
|
922
|
-
});
|
|
925
|
+
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && (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;
|
|
923
926
|
}
|
|
924
927
|
var isMenuOpenNew = isMenuOpen;
|
|
928
|
+
var nextMenuTriggerByNode = (meta === null || meta === void 0 || (_meta$toggleMenu = meta.toggleMenu) === null || _meta$toggleMenu === void 0 ? void 0 : _meta$toggleMenu.triggerByNode) || menuTriggerByNode;
|
|
929
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && tr.docChanged && menuTriggerByNode && !(meta !== null && meta !== void 0 && meta.toggleMenu)) {
|
|
930
|
+
var _menuTriggerByNode$ro, _newState$doc$nodeAt4;
|
|
931
|
+
var mapped = tr.mapping.mapResult(menuTriggerByNode.pos, 1);
|
|
932
|
+
var mappedRoot = tr.mapping.mapResult((_menuTriggerByNode$ro = menuTriggerByNode.rootPos) !== null && _menuTriggerByNode$ro !== void 0 ? _menuTriggerByNode$ro : menuTriggerByNode.pos, 1);
|
|
933
|
+
if (mapped.deleted || mappedRoot.deleted || !((_newState$doc$nodeAt4 = newState.doc.nodeAt(mapped.pos)) !== null && _newState$doc$nodeAt4 !== void 0 && _newState$doc$nodeAt4.isBlock)) {
|
|
934
|
+
nextMenuTriggerByNode = undefined;
|
|
935
|
+
isMenuOpenNew = false;
|
|
936
|
+
} else {
|
|
937
|
+
nextMenuTriggerByNode = _objectSpread(_objectSpread({}, menuTriggerByNode), {}, {
|
|
938
|
+
pos: mapped.pos,
|
|
939
|
+
rootPos: mappedRoot.pos
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
}
|
|
925
943
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
926
944
|
isMenuOpenNew = false;
|
|
927
945
|
} else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
|
|
@@ -941,8 +959,8 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
941
959
|
activeDropTargetNode: currentActiveDropTargetNode,
|
|
942
960
|
isDragging: (_meta$isDragging3 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging3 !== void 0 ? _meta$isDragging3 : isDragging,
|
|
943
961
|
isMenuOpen: isMenuOpenNew,
|
|
944
|
-
menuTriggerBy: (meta === null || meta === void 0 || (_meta$
|
|
945
|
-
menuTriggerByNode:
|
|
962
|
+
menuTriggerBy: (meta === null || meta === void 0 || (_meta$toggleMenu2 = meta.toggleMenu) === null || _meta$toggleMenu2 === void 0 ? void 0 : _meta$toggleMenu2.anchorName) || menuTriggerBy,
|
|
963
|
+
menuTriggerByNode: nextMenuTriggerByNode,
|
|
946
964
|
blockMenuOptions: {
|
|
947
965
|
canMoveUp: (meta === null || meta === void 0 || (_meta$toggleMenu3 = meta.toggleMenu) === null || _meta$toggleMenu3 === void 0 ? void 0 : _meta$toggleMenu3.moveUp) !== undefined ? meta === null || meta === void 0 || (_meta$toggleMenu4 = meta.toggleMenu) === null || _meta$toggleMenu4 === void 0 ? void 0 : _meta$toggleMenu4.moveUp : blockMenuOptions === null || blockMenuOptions === void 0 ? void 0 : blockMenuOptions.canMoveUp,
|
|
948
966
|
canMoveDown: (meta === null || meta === void 0 || (_meta$toggleMenu5 = meta.toggleMenu) === null || _meta$toggleMenu5 === void 0 ? void 0 : _meta$toggleMenu5.moveDown) !== undefined ? meta === null || meta === void 0 || (_meta$toggleMenu6 = meta.toggleMenu) === null || _meta$toggleMenu6 === void 0 ? void 0 : _meta$toggleMenu6.moveDown : blockMenuOptions === null || blockMenuOptions === void 0 ? void 0 : blockMenuOptions.canMoveDown,
|
|
@@ -961,25 +979,17 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
961
979
|
};
|
|
962
980
|
};
|
|
963
981
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
964
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
|
|
965
982
|
var rightSideControlsEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
966
983
|
var quickInsertButtonEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
967
|
-
var legacyDragHandleEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
968
984
|
var _getIntl = getIntl(),
|
|
969
985
|
formatMessage = _getIntl.formatMessage;
|
|
970
986
|
var isAdvancedLayoutEnabled = (0, _editorExperiment.editorExperiment)('advanced_layouts', true, {
|
|
971
987
|
exposure: true
|
|
972
988
|
});
|
|
973
989
|
var toolbarFlagsEnabled = (0, _toolbarFlagCheck.areToolbarFlagsEnabled)(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
974
|
-
// Mirrors `registryBlockControlsEnabled` in blockControlsPlugin.tsx: `legacyDragHandleEnabled` is
|
|
975
|
-
// only false once that gate is on.
|
|
976
|
-
var surfaceNodePositionsEnabled = !legacyDragHandleEnabled;
|
|
977
990
|
var flags = {
|
|
978
|
-
legacyDragHandleEnabled: legacyDragHandleEnabled,
|
|
979
|
-
surfaceNodePositionsEnabled: surfaceNodePositionsEnabled,
|
|
980
991
|
toolbarFlagsEnabled: toolbarFlagsEnabled
|
|
981
992
|
};
|
|
982
|
-
var resolvedSurfaces = surfaceNodePositionsEnabled ? [(0, _surfaceRenderer.resolveSurface)((_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE), (0, _surfaceRenderer.resolveSurface)((_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [], _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)] : [];
|
|
983
993
|
var anchorRectCache;
|
|
984
994
|
if (!(0, _anchorUtils.isAnchorSupported)()) {
|
|
985
995
|
anchorRectCache = new _anchorUtils.AnchorRectCache();
|
|
@@ -993,13 +1003,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
993
1003
|
return new _safePlugin.SafePlugin({
|
|
994
1004
|
key: key,
|
|
995
1005
|
state: {
|
|
996
|
-
init: function init(
|
|
997
|
-
return _objectSpread(
|
|
998
|
-
surfaceNodePositions: resolvedSurfaces.length > 0 ? (0, _surfaceNodePositions.getSurfaceNodePositions)(editorState, resolvedSurfaces) : []
|
|
999
|
-
});
|
|
1006
|
+
init: function init() {
|
|
1007
|
+
return _objectSpread({}, initialState);
|
|
1000
1008
|
},
|
|
1001
1009
|
apply: function apply(tr, currentState, _, newState) {
|
|
1002
|
-
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup,
|
|
1010
|
+
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, limitedModeTeardown);
|
|
1003
1011
|
}
|
|
1004
1012
|
},
|
|
1005
1013
|
props: {
|
|
@@ -1020,7 +1028,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1020
1028
|
var decorationSet = (_key$getState2 = key.getState(state)) === null || _key$getState2 === void 0 ? void 0 : _key$getState2.decorations;
|
|
1021
1029
|
// In view mode with right-side controls, remove any lingering drag-handle decorations
|
|
1022
1030
|
// (created in edit mode) that may not have been cleaned up on mode switch.
|
|
1023
|
-
if (decorationSet &&
|
|
1031
|
+
if (decorationSet && !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && rightSideControlsEnabled && (api === null || api === void 0 || (_api$editorViewMode3 = api.editorViewMode) === null || _api$editorViewMode3 === void 0 || (_api$editorViewMode3 = _api$editorViewMode3.sharedState.currentState()) === null || _api$editorViewMode3 === void 0 ? void 0 : _api$editorViewMode3.mode) === 'view') {
|
|
1024
1032
|
var handleDecs = (0, _decorationsDragHandle.findHandleDec)(decorationSet, 0, state.doc.content.size);
|
|
1025
1033
|
if (handleDecs.length > 0) {
|
|
1026
1034
|
decorationSet = decorationSet.remove(handleDecs);
|
|
@@ -1166,10 +1174,14 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1166
1174
|
// another layer of protection to prevent handling mouseover
|
|
1167
1175
|
// when native anchor with dnd is enabled in limited mode
|
|
1168
1176
|
// in case there are descripancies between getNodeIdProvider limited mode state
|
|
1169
|
-
if ((_getNodeIdProvider = (0, _nodeAnchor.getNodeIdProvider)(view)) !== null && _getNodeIdProvider !== void 0 && _getNodeIdProvider.isLimitedMode() && (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) {
|
|
1177
|
+
if ((_getNodeIdProvider = (0, _nodeAnchor.getNodeIdProvider)(view)) !== null && _getNodeIdProvider !== void 0 && _getNodeIdProvider.isLimitedMode() && ((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) || (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration'))) {
|
|
1170
1178
|
return;
|
|
1171
1179
|
}
|
|
1172
|
-
(0,
|
|
1180
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) {
|
|
1181
|
+
(0, _handleSparseMouseOver.handleSparseMouseOver)(view, event, api);
|
|
1182
|
+
} else {
|
|
1183
|
+
(0, _handleMouseOver.handleMouseOver)(view, event, api);
|
|
1184
|
+
}
|
|
1173
1185
|
return false;
|
|
1174
1186
|
},
|
|
1175
1187
|
mousedown: function mousedown(view, event) {
|
|
@@ -1230,7 +1242,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1230
1242
|
if ((0, _editorExperiment.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
1231
1243
|
var _api$core2;
|
|
1232
1244
|
// Focus moving into the registry surface remains inside the editor experience.
|
|
1233
|
-
var isChildOfSurface =
|
|
1245
|
+
var isChildOfSurface = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest(_consts.BLOCK_CONTROLS_SURFACE_SELECTOR) !== null;
|
|
1234
1246
|
var shouldPreserveRemixInlineDropdownFocus = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest('[data-editor-remix-inline-dropdown-preserve-focus]') !== null;
|
|
1235
1247
|
var isChildOfEditor = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest("#".concat(_ui.EDIT_AREA_ID)) !== null;
|
|
1236
1248
|
|
|
@@ -1270,7 +1282,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1270
1282
|
|
|
1271
1283
|
// Registry surfaces have their own ResizeObservers and absolute placement.
|
|
1272
1284
|
// Width metadata only drives legacy widget recreation.
|
|
1273
|
-
if (
|
|
1285
|
+
if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration') && !isResizerResizing) {
|
|
1274
1286
|
var _editorContentArea2 = entries[0].target;
|
|
1275
1287
|
// Ignored via go/ees005
|
|
1276
1288
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1289,7 +1301,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1289
1301
|
}
|
|
1290
1302
|
}
|
|
1291
1303
|
}));
|
|
1292
|
-
var shouldObserve = (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)
|
|
1304
|
+
var shouldObserve = !((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true) || (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) || !(0, _anchorUtils.isAnchorSupported)();
|
|
1293
1305
|
if (editorContentArea && shouldObserve) {
|
|
1294
1306
|
resizeObserverWidth.observe(editorContentArea);
|
|
1295
1307
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sparseSurfacesKey = exports.createSparseSurfacesPlugin = void 0;
|
|
7
|
+
var _surfaceCandidateInvalidation = require("@atlaskit/editor-common/block-controls/surface-candidate-invalidation");
|
|
8
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
9
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
|
+
var _view2 = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _main = require("./main");
|
|
12
|
+
var _sparseSurfaceCandidates = require("./utils/sparse-surface-candidates");
|
|
13
|
+
var _sparseSurfacesState = require("./utils/sparse-surfaces-state");
|
|
14
|
+
var _sparseSurfacesView = require("./utils/sparse-surfaces-view");
|
|
15
|
+
var sparseSurfacesKey = exports.sparseSurfacesKey = new _state.PluginKey('blockControlsSparseSurfaces');
|
|
16
|
+
|
|
17
|
+
/** Owns sparse anchors independently of drag/drop decorations and their lifecycle. */
|
|
18
|
+
var createSparseSurfacesPlugin = exports.createSparseSurfacesPlugin = function createSparseSurfacesPlugin(api) {
|
|
19
|
+
return new _safePlugin.SafePlugin({
|
|
20
|
+
key: sparseSurfacesKey,
|
|
21
|
+
state: {
|
|
22
|
+
init: function init() {
|
|
23
|
+
return (0, _sparseSurfacesState.createInitialSparseSurfacesState)(_sparseSurfaceCandidates.emptySparseSurfaceCandidateState);
|
|
24
|
+
},
|
|
25
|
+
apply: function apply(tr, previous, _oldState, newState) {
|
|
26
|
+
return (0, _sparseSurfacesState.applySparseSurfacesTransaction)({
|
|
27
|
+
invalidation: tr.getMeta(_surfaceCandidateInvalidation.BLOCK_CONTROLS_SURFACE_INVALIDATION),
|
|
28
|
+
meta: tr.getMeta(sparseSurfacesKey),
|
|
29
|
+
newState: newState,
|
|
30
|
+
previous: previous,
|
|
31
|
+
tr: tr
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
props: {
|
|
36
|
+
decorations: function decorations(state) {
|
|
37
|
+
var _api$limitedMode, _blockControlsKey$get, _sparseSurfacesKey$ge;
|
|
38
|
+
return 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 && _api$limitedMode.enabled || (_blockControlsKey$get = _main.key.getState(state)) !== null && _blockControlsKey$get !== void 0 && _blockControlsKey$get.isDragging ? _view2.DecorationSet.empty : (_sparseSurfacesKey$ge = sparseSurfacesKey.getState(state)) === null || _sparseSurfacesKey$ge === void 0 ? void 0 : _sparseSurfacesKey$ge.decorations;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
view: function view(_view) {
|
|
42
|
+
return (0, _sparseSurfacesView.createSparseSurfacesView)({
|
|
43
|
+
api: api,
|
|
44
|
+
pluginKey: sparseSurfacesKey,
|
|
45
|
+
view: _view
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|