@atlaskit/editor-plugin-block-controls 20.1.2 → 20.1.4
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 +18 -0
- package/dist/cjs/pm-plugins/selection-preservation/pm-plugin.js +17 -34
- package/dist/cjs/ui/block-controls-left-surface.compiled.css +7 -1
- package/dist/cjs/ui/block-controls-left-surface.js +41 -27
- package/dist/cjs/ui/block-controls-left-surfaces.js +32 -12
- package/dist/cjs/ui/block-controls-right-surface.js +32 -24
- package/dist/cjs/ui/block-controls-right-surfaces.js +6 -4
- package/dist/cjs/ui/block-controls-surface-components.js +142 -0
- package/dist/cjs/ui/utils/get-surface-placement.js +63 -16
- package/dist/cjs/ui/visibility-container.js +42 -7
- package/dist/es2019/pm-plugins/selection-preservation/pm-plugin.js +17 -34
- package/dist/es2019/ui/block-controls-left-surface.compiled.css +7 -1
- package/dist/es2019/ui/block-controls-left-surface.js +44 -29
- package/dist/es2019/ui/block-controls-left-surfaces.js +41 -16
- package/dist/es2019/ui/block-controls-right-surface.js +35 -26
- package/dist/es2019/ui/block-controls-right-surfaces.js +6 -4
- package/dist/es2019/ui/block-controls-surface-components.js +129 -0
- package/dist/es2019/ui/utils/get-surface-placement.js +59 -7
- package/dist/es2019/ui/visibility-container.js +44 -6
- package/dist/esm/pm-plugins/selection-preservation/pm-plugin.js +17 -34
- package/dist/esm/ui/block-controls-left-surface.compiled.css +7 -1
- package/dist/esm/ui/block-controls-left-surface.js +43 -29
- package/dist/esm/ui/block-controls-left-surfaces.js +33 -13
- package/dist/esm/ui/block-controls-right-surface.js +34 -26
- package/dist/esm/ui/block-controls-right-surfaces.js +6 -4
- package/dist/esm/ui/block-controls-surface-components.js +133 -0
- package/dist/esm/ui/utils/get-surface-placement.js +62 -15
- package/dist/esm/ui/visibility-container.js +41 -6
- package/dist/types/ui/block-controls-surface-components.d.ts +13 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +13 -0
- package/dist/types/ui/visibility-container.d.ts +14 -0
- package/package.json +3 -3
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getBlockControlsRightSurfaceComponents = exports.getBlockControlsLeftSurfaceComponents = exports.BlockControlsVisibilityProvider = void 0;
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
14
|
+
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
15
|
+
var _partitionComponentsByPersistence = require("./utils/partition-components-by-persistence");
|
|
16
|
+
var _visibilityContainer = require("./visibility-container");
|
|
17
|
+
var _excluded = ["isHidden"];
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
+
var BlockControlsVisibilityContext = /*#__PURE__*/(0, _react.createContext)({
|
|
22
|
+
shouldHideHoverControls: false,
|
|
23
|
+
useCssStyles: false
|
|
24
|
+
});
|
|
25
|
+
var BlockControlItem = function BlockControlItem(_ref) {
|
|
26
|
+
var children = _ref.children;
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
28
|
+
"data-editor-block-control-item": true
|
|
29
|
+
}, children);
|
|
30
|
+
};
|
|
31
|
+
var HoverBlockControlItem = function HoverBlockControlItem(_ref2) {
|
|
32
|
+
var children = _ref2.children;
|
|
33
|
+
var _useContext = (0, _react.useContext)(BlockControlsVisibilityContext),
|
|
34
|
+
shouldHideHoverControls = _useContext.shouldHideHoverControls,
|
|
35
|
+
useCssStyles = _useContext.useCssStyles;
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement(BlockControlItem, null, /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityWrapper, {
|
|
37
|
+
shouldHide: shouldHideHoverControls,
|
|
38
|
+
useCssStyles: useCssStyles
|
|
39
|
+
}, children));
|
|
40
|
+
};
|
|
41
|
+
var PersistentBlockControlItem = function PersistentBlockControlItem(_ref3) {
|
|
42
|
+
var children = _ref3.children;
|
|
43
|
+
var _useContext2 = (0, _react.useContext)(BlockControlsVisibilityContext),
|
|
44
|
+
useCssStyles = _useContext2.useCssStyles;
|
|
45
|
+
return /*#__PURE__*/_react.default.createElement(BlockControlItem, null, /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityWrapper, {
|
|
46
|
+
shouldHide: false,
|
|
47
|
+
useCssStyles: useCssStyles
|
|
48
|
+
}, children));
|
|
49
|
+
};
|
|
50
|
+
var BlockControlsVisibilityProvider = exports.BlockControlsVisibilityProvider = function BlockControlsVisibilityProvider(_ref4) {
|
|
51
|
+
var children = _ref4.children,
|
|
52
|
+
shouldHideHoverControls = _ref4.shouldHideHoverControls,
|
|
53
|
+
useCssStyles = _ref4.useCssStyles;
|
|
54
|
+
var value = (0, _react.useMemo)(function () {
|
|
55
|
+
return {
|
|
56
|
+
shouldHideHoverControls: shouldHideHoverControls,
|
|
57
|
+
useCssStyles: useCssStyles
|
|
58
|
+
};
|
|
59
|
+
}, [shouldHideHoverControls, useCssStyles]);
|
|
60
|
+
return /*#__PURE__*/_react.default.createElement(BlockControlsVisibilityContext.Provider, {
|
|
61
|
+
value: value
|
|
62
|
+
}, children);
|
|
63
|
+
};
|
|
64
|
+
var withoutVisibilityPredicate = function withoutVisibilityPredicate(component) {
|
|
65
|
+
var _isHidden = component.isHidden,
|
|
66
|
+
visibleComponent = (0, _objectWithoutProperties2.default)(component, _excluded);
|
|
67
|
+
return visibleComponent;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Replaces the shared surface group with one stable wrapper group per visible control. The wrappers
|
|
72
|
+
* inherit each control's rank, so SurfaceRenderer keeps the registry order without re-evaluating
|
|
73
|
+
* the controls' visibility predicates.
|
|
74
|
+
*/
|
|
75
|
+
var getBlockControlsSurfaceComponents = function getBlockControlsSurfaceComponents(components, _ref5, surfaceContext) {
|
|
76
|
+
var _resolvedSurface$chil;
|
|
77
|
+
var group = _ref5.group,
|
|
78
|
+
section = _ref5.section,
|
|
79
|
+
surface = _ref5.surface;
|
|
80
|
+
var resolvedSurface = (0, _surfaceRenderer.resolveSurface)(components, surface);
|
|
81
|
+
var groupIdentity = (0, _surfaceRenderer.getComponentIdentity)(group);
|
|
82
|
+
var controls = (_resolvedSurface$chil = resolvedSurface.childrenMap.get(groupIdentity)) !== null && _resolvedSurface$chil !== void 0 ? _resolvedSurface$chil : [];
|
|
83
|
+
var visibleControls = controls.filter(function (control) {
|
|
84
|
+
var _control$isHidden, _control$isHidden2;
|
|
85
|
+
return !((_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
|
|
86
|
+
surfaceContext: surfaceContext
|
|
87
|
+
})) !== null && _control$isHidden !== void 0 ? _control$isHidden : false);
|
|
88
|
+
});
|
|
89
|
+
if (!resolvedSurface.root || visibleControls.length === 0) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
var controlIdentities = new Set(controls.map(_surfaceRenderer.getComponentIdentity));
|
|
93
|
+
var visibleControlIdentities = new Set(visibleControls.map(_surfaceRenderer.getComponentIdentity));
|
|
94
|
+
var _partitionComponentsB = (0, _partitionComponentsByPersistence.partitionComponentsByPersistence)(resolvedSurface.components.filter(function (component) {
|
|
95
|
+
var identity = (0, _surfaceRenderer.getComponentIdentity)(component);
|
|
96
|
+
return !controlIdentities.has(identity) || visibleControlIdentities.has(identity);
|
|
97
|
+
}), surface, surfaceContext),
|
|
98
|
+
persistentComponents = _partitionComponentsB.persistentComponents;
|
|
99
|
+
var persistentIdentities = new Set(persistentComponents.map(_surfaceRenderer.getComponentIdentity));
|
|
100
|
+
var structuralComponents = resolvedSurface.components.filter(function (component) {
|
|
101
|
+
var identity = (0, _surfaceRenderer.getComponentIdentity)(component);
|
|
102
|
+
return identity !== groupIdentity && !controlIdentities.has(identity);
|
|
103
|
+
}).map(withoutVisibilityPredicate);
|
|
104
|
+
var wrappedControls = visibleControls.flatMap(function (control) {
|
|
105
|
+
var _control$parents$find, _control$parents;
|
|
106
|
+
var identity = (0, _surfaceRenderer.getComponentIdentity)(control);
|
|
107
|
+
var rank = (_control$parents$find = (_control$parents = control.parents) === null || _control$parents === void 0 || (_control$parents = _control$parents.find(function (parent) {
|
|
108
|
+
return (0, _surfaceRenderer.getComponentIdentity)(parent) === groupIdentity;
|
|
109
|
+
})) === null || _control$parents === void 0 ? void 0 : _control$parents.rank) !== null && _control$parents$find !== void 0 ? _control$parents$find : 0;
|
|
110
|
+
var wrapper = {
|
|
111
|
+
component: persistentIdentities.has(identity) ? PersistentBlockControlItem : HoverBlockControlItem,
|
|
112
|
+
key: "block-control-item:".concat(identity),
|
|
113
|
+
parents: [_objectSpread(_objectSpread({}, section), {}, {
|
|
114
|
+
rank: rank
|
|
115
|
+
})],
|
|
116
|
+
type: 'group'
|
|
117
|
+
};
|
|
118
|
+
var visibleControl = _objectSpread(_objectSpread({}, withoutVisibilityPredicate(control)), {}, {
|
|
119
|
+
parents: [{
|
|
120
|
+
key: wrapper.key,
|
|
121
|
+
rank: 0,
|
|
122
|
+
type: wrapper.type
|
|
123
|
+
}]
|
|
124
|
+
});
|
|
125
|
+
return [wrapper, visibleControl];
|
|
126
|
+
});
|
|
127
|
+
return [].concat((0, _toConsumableArray2.default)(structuralComponents), (0, _toConsumableArray2.default)(wrappedControls));
|
|
128
|
+
};
|
|
129
|
+
var getBlockControlsLeftSurfaceComponents = exports.getBlockControlsLeftSurfaceComponents = function getBlockControlsLeftSurfaceComponents(components, surfaceContext) {
|
|
130
|
+
return getBlockControlsSurfaceComponents(components, {
|
|
131
|
+
group: _surfaceKeys.BLOCK_CONTROLS_LEFT_GROUP,
|
|
132
|
+
section: _surfaceKeys.BLOCK_CONTROLS_LEFT_SECTION,
|
|
133
|
+
surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE
|
|
134
|
+
}, surfaceContext);
|
|
135
|
+
};
|
|
136
|
+
var getBlockControlsRightSurfaceComponents = exports.getBlockControlsRightSurfaceComponents = function getBlockControlsRightSurfaceComponents(components, surfaceContext) {
|
|
137
|
+
return getBlockControlsSurfaceComponents(components, {
|
|
138
|
+
group: _surfaceKeys.BLOCK_CONTROLS_RIGHT_GROUP,
|
|
139
|
+
section: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SECTION,
|
|
140
|
+
surface: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE
|
|
141
|
+
}, surfaceContext);
|
|
142
|
+
};
|
|
@@ -4,10 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.toMeasuredSurfaceWrapperPlacement = exports.getSurfacePlacement = exports.getAnchoredSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
|
|
7
|
+
exports.toMeasuredSurfaceWrapperPlacement = exports.getSurfacePlacement = exports.getLeftGutterSurfacePlacement = exports.getAnchoredSurfacePlacement = exports.getAnchoredLeftGutterSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
8
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _dragHandlePositions = require("../../pm-plugins/utils/drag-handle-positions");
|
|
10
11
|
var _consts = require("../consts");
|
|
12
|
+
var _excluded = ["leftGutterBoundary"];
|
|
11
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
15
|
var getAbsoluteSurfacePlacement = exports.getAbsoluteSurfacePlacement = function getAbsoluteSurfacePlacement(_ref) {
|
|
@@ -50,18 +52,40 @@ var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlace
|
|
|
50
52
|
var gap = (0, _consts.dragHandleGap)(nodeType, parentNodeType);
|
|
51
53
|
var top = nodeRect.top + (0, _consts.topPositionAdjustment)(nodeTypeWithLevel, layout);
|
|
52
54
|
var height = (0, _dragHandlePositions.shouldBeSticky)(nodeType) ? nodeRect.height : undefined;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (side === 'right') {
|
|
56
|
+
return {
|
|
57
|
+
left: nodeRect.right + gap,
|
|
58
|
+
top: top,
|
|
59
|
+
transform: '',
|
|
60
|
+
height: height
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
59
64
|
left: nodeRect.left,
|
|
60
65
|
top: top,
|
|
61
66
|
transform: "translateX(calc(-100% - ".concat(gap, "px))"),
|
|
62
67
|
height: height
|
|
63
68
|
};
|
|
64
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Expands a measured left surface from the available gutter boundary to the target node.
|
|
72
|
+
*/
|
|
73
|
+
var getLeftGutterSurfacePlacement = exports.getLeftGutterSurfacePlacement = function getLeftGutterSurfacePlacement(_ref3) {
|
|
74
|
+
var leftGutterBoundary = _ref3.leftGutterBoundary,
|
|
75
|
+
options = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
|
|
76
|
+
var placement = getSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
|
|
77
|
+
side: 'left'
|
|
78
|
+
}));
|
|
79
|
+
if (options.nodeType === 'layoutColumn') {
|
|
80
|
+
return placement;
|
|
81
|
+
}
|
|
82
|
+
var gap = (0, _consts.dragHandleGap)(options.nodeType, options.parentNodeType);
|
|
83
|
+
return _objectSpread(_objectSpread({}, placement), {}, {
|
|
84
|
+
left: leftGutterBoundary,
|
|
85
|
+
transform: '',
|
|
86
|
+
width: Math.max(0, options.nodeRect.left - leftGutterBoundary - gap)
|
|
87
|
+
});
|
|
88
|
+
};
|
|
65
89
|
|
|
66
90
|
/**
|
|
67
91
|
* The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
|
|
@@ -82,12 +106,14 @@ var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlace
|
|
|
82
106
|
var toMeasuredSurfaceWrapperPlacement = exports.toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapperPlacement(placement) {
|
|
83
107
|
return {
|
|
84
108
|
isSticky: placement.height !== undefined,
|
|
85
|
-
style: {
|
|
109
|
+
style: _objectSpread({
|
|
86
110
|
height: placement.height,
|
|
87
111
|
left: placement.left,
|
|
88
112
|
top: placement.top,
|
|
89
113
|
transform: placement.transform
|
|
90
|
-
}
|
|
114
|
+
}, placement.width !== undefined ? {
|
|
115
|
+
width: placement.width
|
|
116
|
+
} : {})
|
|
91
117
|
};
|
|
92
118
|
};
|
|
93
119
|
|
|
@@ -103,13 +129,13 @@ var toMeasuredSurfaceWrapperPlacement = exports.toMeasuredSurfaceWrapperPlacemen
|
|
|
103
129
|
var INVALID_ANCHOR_OFFSCREEN_PX = 9999;
|
|
104
130
|
var INVALID_ANCHOR_FALLBACK_TOP = "-".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
|
|
105
131
|
var INVALID_ANCHOR_FALLBACK_BOTTOM = "".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
|
|
106
|
-
var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(
|
|
107
|
-
var anchorName =
|
|
108
|
-
layout =
|
|
109
|
-
nodeType =
|
|
110
|
-
nodeTypeWithLevel =
|
|
111
|
-
parentNodeType =
|
|
112
|
-
side =
|
|
132
|
+
var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref4) {
|
|
133
|
+
var anchorName = _ref4.anchorName,
|
|
134
|
+
layout = _ref4.layout,
|
|
135
|
+
nodeType = _ref4.nodeType,
|
|
136
|
+
nodeTypeWithLevel = _ref4.nodeTypeWithLevel,
|
|
137
|
+
parentNodeType = _ref4.parentNodeType,
|
|
138
|
+
side = _ref4.side;
|
|
113
139
|
if (nodeType === 'layoutColumn') {
|
|
114
140
|
// The column's horizontal midpoint, matching the measured `nodeRect.left + width / 2` and the
|
|
115
141
|
// legacy drag handle's own layout-column formula. Side-independent.
|
|
@@ -139,4 +165,25 @@ var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function
|
|
|
139
165
|
transform: side === 'right' ? '' : "translateX(calc(-100% - ".concat(gap, "px))")
|
|
140
166
|
})
|
|
141
167
|
};
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Expands an anchored left surface across the available gutter without runtime measurement.
|
|
171
|
+
*/
|
|
172
|
+
var getAnchoredLeftGutterSurfacePlacement = exports.getAnchoredLeftGutterSurfacePlacement = function getAnchoredLeftGutterSurfacePlacement(options) {
|
|
173
|
+
var placement = getAnchoredSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
|
|
174
|
+
side: 'left'
|
|
175
|
+
}));
|
|
176
|
+
if (options.nodeType === 'layoutColumn') {
|
|
177
|
+
return placement;
|
|
178
|
+
}
|
|
179
|
+
var gap = (0, _consts.dragHandleGap)(options.nodeType, options.parentNodeType);
|
|
180
|
+
return _objectSpread(_objectSpread({}, placement), {}, {
|
|
181
|
+
style: _objectSpread(_objectSpread({}, placement.style), {}, {
|
|
182
|
+
left: 0,
|
|
183
|
+
// In a `right` inset, `anchor(... left)` resolves from the containing block's right edge
|
|
184
|
+
// to the anchor's left edge. Adding the gap ends this wrapper just before the node.
|
|
185
|
+
right: "calc(anchor(".concat(options.anchorName, " left) + ").concat(gap, "px)"),
|
|
186
|
+
transform: ''
|
|
187
|
+
})
|
|
188
|
+
});
|
|
142
189
|
};
|
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.VisibilityContainer = void 0;
|
|
8
|
+
exports.useBlockControlsVisibility = exports.VisibilityWrapper = exports.VisibilityContainer = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -57,13 +57,16 @@ var hiddenStylesCSS = (0, _react2.css)({
|
|
|
57
57
|
var displayContentsStylesCSS = (0, _react2.css)({
|
|
58
58
|
display: 'contents'
|
|
59
59
|
});
|
|
60
|
-
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Resolves visibility once so a surface can apply the same state to each rendered control without
|
|
63
|
+
* creating a plugin-state subscription and hide-delay timer for every control wrapper.
|
|
64
|
+
*/
|
|
65
|
+
var useBlockControlsVisibility = exports.useBlockControlsVisibility = function useBlockControlsVisibility(_ref) {
|
|
61
66
|
var api = _ref.api,
|
|
62
|
-
children = _ref.children,
|
|
63
67
|
controlSide = _ref.controlSide,
|
|
64
68
|
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
65
|
-
isPersistent = _ref.isPersistent
|
|
66
|
-
shouldUseDisplayContents = _ref.shouldUseDisplayContents;
|
|
69
|
+
isPersistent = _ref.isPersistent;
|
|
67
70
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['typeAhead', 'blockControls', 'editorViewMode', 'userIntent', 'showDiff'], function (states) {
|
|
68
71
|
var _states$typeAheadStat, _states$blockControls, _states$blockControls2, _states$blockControls3, _states$editorViewMod, _states$userIntentSta, _states$showDiffState, _states$blockControls4;
|
|
69
72
|
return {
|
|
@@ -139,9 +142,20 @@ var VisibilityContainer = exports.VisibilityContainer = function VisibilityConta
|
|
|
139
142
|
};
|
|
140
143
|
}, [shouldHideImmediate, isRightControlViewMode]);
|
|
141
144
|
var shouldHide = isRightControlViewMode ? delayedShouldHide : shouldHideImmediate;
|
|
142
|
-
|
|
145
|
+
var useCssStyles = (0, _editorExperiment.editorExperiment)('platform_editor_preview_panel_responsiveness', true, {
|
|
143
146
|
exposure: true
|
|
144
|
-
})
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
shouldHide: shouldHide,
|
|
150
|
+
useCssStyles: useCssStyles
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
var VisibilityWrapper = exports.VisibilityWrapper = function VisibilityWrapper(_ref2) {
|
|
154
|
+
var children = _ref2.children,
|
|
155
|
+
shouldHide = _ref2.shouldHide,
|
|
156
|
+
shouldUseDisplayContents = _ref2.shouldUseDisplayContents,
|
|
157
|
+
useCssStyles = _ref2.useCssStyles;
|
|
158
|
+
if (useCssStyles) {
|
|
145
159
|
return (0, _react2.jsx)("div", {
|
|
146
160
|
css: [baseStylesCSS, shouldHide ? hiddenStylesCSS : visibleStylesCSS, shouldUseDisplayContents && displayContentsStylesCSS]
|
|
147
161
|
}, children);
|
|
@@ -151,4 +165,25 @@ var VisibilityContainer = exports.VisibilityContainer = function VisibilityConta
|
|
|
151
165
|
, {
|
|
152
166
|
xcss: [baseStyles, shouldHide ? hiddenStyles : visibleStyles, shouldUseDisplayContents && displayContentsStyles]
|
|
153
167
|
}, children);
|
|
168
|
+
};
|
|
169
|
+
var VisibilityContainer = exports.VisibilityContainer = function VisibilityContainer(_ref3) {
|
|
170
|
+
var api = _ref3.api,
|
|
171
|
+
children = _ref3.children,
|
|
172
|
+
controlSide = _ref3.controlSide,
|
|
173
|
+
forceVisibleOnMouseOut = _ref3.forceVisibleOnMouseOut,
|
|
174
|
+
isPersistent = _ref3.isPersistent,
|
|
175
|
+
shouldUseDisplayContents = _ref3.shouldUseDisplayContents;
|
|
176
|
+
var _useBlockControlsVisi = useBlockControlsVisibility({
|
|
177
|
+
api: api,
|
|
178
|
+
controlSide: controlSide,
|
|
179
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
180
|
+
isPersistent: isPersistent
|
|
181
|
+
}),
|
|
182
|
+
shouldHide = _useBlockControlsVisi.shouldHide,
|
|
183
|
+
useCssStyles = _useBlockControlsVisi.useCssStyles;
|
|
184
|
+
return (0, _react2.jsx)(VisibilityWrapper, {
|
|
185
|
+
shouldHide: shouldHide,
|
|
186
|
+
shouldUseDisplayContents: shouldUseDisplayContents,
|
|
187
|
+
useCssStyles: useCssStyles
|
|
188
|
+
}, children);
|
|
154
189
|
};
|
|
@@ -2,7 +2,6 @@ import { bind } from 'bind-event-listener';
|
|
|
2
2
|
import { getDocument } from '@atlaskit/browser-apis';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import { DRAG_HANDLE_SELECTOR } from '@atlaskit/editor-common/styles';
|
|
5
|
-
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
5
|
import { key } from '../main';
|
|
7
6
|
import { createPreservedSelection, mapPreservedSelection } from '../utils/selection';
|
|
8
7
|
import { stopPreservingSelection } from './editor-commands';
|
|
@@ -44,16 +43,10 @@ export const createSelectionPreservationPlugin = api => () => {
|
|
|
44
43
|
key: selectionPreservationPluginKey,
|
|
45
44
|
state: {
|
|
46
45
|
init() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
} else {
|
|
53
|
-
return {
|
|
54
|
-
preservedSelection: undefined
|
|
55
|
-
};
|
|
56
|
-
}
|
|
46
|
+
return {
|
|
47
|
+
preservedSelection: undefined,
|
|
48
|
+
syncDomSelectionForDoc: undefined
|
|
49
|
+
};
|
|
57
50
|
},
|
|
58
51
|
apply(tr, pluginState) {
|
|
59
52
|
const meta = getSelectionPreservationMeta(tr);
|
|
@@ -62,21 +55,15 @@ export const createSelectionPreservationPlugin = api => () => {
|
|
|
62
55
|
};
|
|
63
56
|
if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'startPreserving') {
|
|
64
57
|
newState.preservedSelection = createPreservedSelection(tr.doc.resolve(tr.selection.from), tr.doc.resolve(tr.selection.to));
|
|
65
|
-
|
|
66
|
-
newState.syncDomSelectionForDoc = undefined;
|
|
67
|
-
}
|
|
58
|
+
newState.syncDomSelectionForDoc = undefined;
|
|
68
59
|
} else if ((meta === null || meta === void 0 ? void 0 : meta.type) === 'stopPreserving') {
|
|
69
60
|
newState.preservedSelection = undefined;
|
|
70
|
-
|
|
71
|
-
newState.syncDomSelectionForDoc = undefined;
|
|
72
|
-
}
|
|
61
|
+
newState.syncDomSelectionForDoc = undefined;
|
|
73
62
|
} else if (tr.docChanged) {
|
|
74
63
|
if (newState.preservedSelection) {
|
|
75
64
|
newState.preservedSelection = mapPreservedSelection(newState.preservedSelection, tr);
|
|
76
65
|
}
|
|
77
|
-
|
|
78
|
-
newState.syncDomSelectionForDoc = hasFormatSelectionSyncMeta(tr) ? tr.doc : undefined;
|
|
79
|
-
}
|
|
66
|
+
newState.syncDomSelectionForDoc = hasFormatSelectionSyncMeta(tr) ? tr.doc : undefined;
|
|
80
67
|
}
|
|
81
68
|
if (!compareSelections(newState.preservedSelection, pluginState.preservedSelection)) {
|
|
82
69
|
if (newState.preservedSelection) {
|
|
@@ -187,23 +174,19 @@ export const createSelectionPreservationPlugin = api => () => {
|
|
|
187
174
|
const activeNodeChanged = prevActiveNode !== currActiveNode;
|
|
188
175
|
const docChanged = prevState.doc !== view.state.doc;
|
|
189
176
|
const hasFormatSyncRequestForCurrentDoc = (currPluginState === null || currPluginState === void 0 ? void 0 : currPluginState.syncDomSelectionForDoc) === view.state.doc;
|
|
190
|
-
const shouldSyncDOMSelection = (hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) ||
|
|
177
|
+
const shouldSyncDOMSelection = (hasPreservedSelection && (preservedSelectionChanged || activeNodeChanged) || hasFormatSyncRequestForCurrentDoc) && docChanged;
|
|
191
178
|
if (shouldSyncDOMSelection) {
|
|
192
179
|
const syncSelection = view.state.selection;
|
|
193
|
-
if (
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
cancelAnimationFrame(pendingFormatSelectionSyncFrame);
|
|
197
|
-
}
|
|
198
|
-
pendingFormatSelectionSyncFrame = requestAnimationFrame(() => {
|
|
199
|
-
pendingFormatSelectionSyncFrame = undefined;
|
|
200
|
-
syncDOMSelection(syncSelection, view, {
|
|
201
|
-
focusEditor: true
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
} else {
|
|
205
|
-
syncDOMSelection(syncSelection, view);
|
|
180
|
+
if (hasFormatSyncRequestForCurrentDoc) {
|
|
181
|
+
if (pendingFormatSelectionSyncFrame !== undefined) {
|
|
182
|
+
cancelAnimationFrame(pendingFormatSelectionSyncFrame);
|
|
206
183
|
}
|
|
184
|
+
pendingFormatSelectionSyncFrame = requestAnimationFrame(() => {
|
|
185
|
+
pendingFormatSelectionSyncFrame = undefined;
|
|
186
|
+
syncDOMSelection(syncSelection, view, {
|
|
187
|
+
focusEditor: true
|
|
188
|
+
});
|
|
189
|
+
});
|
|
207
190
|
} else {
|
|
208
191
|
syncDOMSelection(syncSelection, view);
|
|
209
192
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
._zulpv77o{gap:var(--ds-space-025,2px)}._154iu2gc{top:var(--ds-space-100,8px)}
|
|
2
2
|
._17c61i8t{position-visibility:anchors-valid}
|
|
3
|
+
._1bahesu3{justify-content:flex-end}
|
|
3
4
|
._1e0c1txw{display:flex}
|
|
5
|
+
._1f38ffwv{container-name:block-controls-left-gutter}
|
|
4
6
|
._1pbyb4wl{z-index:100}
|
|
5
7
|
._4cvr1h6o{align-items:center}
|
|
8
|
+
._7cca15wb{container-type:inline-size}
|
|
6
9
|
._kqsw1if8{position:sticky}
|
|
7
|
-
._kqswstnw{position:absolute}
|
|
10
|
+
._kqswstnw{position:absolute}
|
|
11
|
+
._lcxvglyw{pointer-events:none}
|
|
12
|
+
._w1y61wug>*{pointer-events:auto}
|
|
13
|
+
@container block-controls-left-gutter (max-width: 67px){._19vrglyw>[data-editor-block-control-item]:nth-last-child(n+3){display:none}}
|
|
@@ -4,12 +4,16 @@ import { ax, ix } from "@compiled/react/runtime";
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
6
6
|
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
7
|
-
import { SurfaceRenderer
|
|
7
|
+
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
8
8
|
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
9
|
+
import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
|
|
9
10
|
import { getBlockControlsSurfaceControlSide } from './block-controls-surface-context';
|
|
10
|
-
import {
|
|
11
|
-
import { VisibilityContainer } from './visibility-container';
|
|
11
|
+
import { useBlockControlsVisibility } from './visibility-container';
|
|
12
12
|
const leftSurfaceOuterStyles = null;
|
|
13
|
+
const leftSurfaceGutterStyles = {
|
|
14
|
+
container: "_1f38ffwv _7cca15wb _lcxvglyw",
|
|
15
|
+
row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
|
|
16
|
+
};
|
|
13
17
|
const leftSurfaceRowStyles = null;
|
|
14
18
|
|
|
15
19
|
// Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
|
|
@@ -17,8 +21,7 @@ const leftSurfaceRowStyles = null;
|
|
|
17
21
|
// can stick near the top of the viewport instead of scrolling off with the node's top edge.
|
|
18
22
|
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
|
|
19
23
|
const leftSurfaceStickyStyles = null;
|
|
20
|
-
|
|
21
|
-
export const BlockControlsLeftSurface = ({
|
|
24
|
+
const BlockControlsLeftSurfaceContent = ({
|
|
22
25
|
api,
|
|
23
26
|
components,
|
|
24
27
|
forceVisibleOnMouseOut,
|
|
@@ -26,16 +29,18 @@ export const BlockControlsLeftSurface = ({
|
|
|
26
29
|
source,
|
|
27
30
|
surfaceContext
|
|
28
31
|
}) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
+
const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
|
|
33
|
+
const controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor'));
|
|
32
34
|
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} =
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
shouldHide: shouldHideHoverControls,
|
|
36
|
+
useCssStyles
|
|
37
|
+
} = useBlockControlsVisibility({
|
|
38
|
+
api,
|
|
39
|
+
controlSide,
|
|
40
|
+
forceVisibleOnMouseOut
|
|
41
|
+
});
|
|
38
42
|
const isSticky = placement.isSticky;
|
|
43
|
+
const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
|
|
39
44
|
return /*#__PURE__*/React.createElement("div", {
|
|
40
45
|
"data-editor-block-controls-surface": true,
|
|
41
46
|
"data-editor-block-controls-side": "left",
|
|
@@ -43,27 +48,37 @@ export const BlockControlsLeftSurface = ({
|
|
|
43
48
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved per target node, from its runtime DOM geometry or from its CSS anchor.
|
|
44
49
|
,
|
|
45
50
|
style: placement.style,
|
|
46
|
-
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
51
|
+
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
|
|
47
52
|
}, /*#__PURE__*/React.createElement("div", {
|
|
48
|
-
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
53
|
-
shouldUseDisplayContents: true
|
|
53
|
+
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc"])
|
|
54
|
+
}, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
|
|
55
|
+
shouldHideHoverControls: shouldHideHoverControls,
|
|
56
|
+
useCssStyles: useCssStyles
|
|
54
57
|
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
55
|
-
components:
|
|
58
|
+
components: components,
|
|
56
59
|
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
57
60
|
surfaceContext: surfaceContext
|
|
58
|
-
}))
|
|
61
|
+
}))));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Renders one left block-controls surface at a document position. */
|
|
65
|
+
export const BlockControlsLeftSurface = ({
|
|
66
|
+
api,
|
|
67
|
+
components,
|
|
68
|
+
forceVisibleOnMouseOut,
|
|
69
|
+
placement,
|
|
70
|
+
source,
|
|
71
|
+
surfaceContext
|
|
72
|
+
}) => {
|
|
73
|
+
if (!placement) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
|
|
59
77
|
api: api,
|
|
60
|
-
|
|
78
|
+
components: components,
|
|
61
79
|
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
65
|
-
components: persistentComponents,
|
|
66
|
-
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
80
|
+
placement: placement,
|
|
81
|
+
source: source,
|
|
67
82
|
surfaceContext: surfaceContext
|
|
68
|
-
})
|
|
83
|
+
});
|
|
69
84
|
};
|