@atlaskit/editor-plugin-block-controls 20.1.3 → 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 +10 -0
- 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/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/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 +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 20.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`48f6e385c3e64`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/48f6e385c3e64) -
|
|
8
|
+
Wrap visible left and right block controls in registry order and, under
|
|
9
|
+
platform_editor_collapsible_headings, hide lower-ranked left controls when a top-level gutter only
|
|
10
|
+
has room for two.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 20.1.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -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}}
|
|
@@ -13,10 +13,14 @@ var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/blo
|
|
|
13
13
|
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
14
14
|
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
15
15
|
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
16
|
+
var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
|
|
16
17
|
var _blockControlsSurfaceContext = require("./block-controls-surface-context");
|
|
17
|
-
var _partitionComponentsByPersistence = require("./utils/partition-components-by-persistence");
|
|
18
18
|
var _visibilityContainer = require("./visibility-container");
|
|
19
19
|
var leftSurfaceOuterStyles = null;
|
|
20
|
+
var leftSurfaceGutterStyles = {
|
|
21
|
+
container: "_1f38ffwv _7cca15wb _lcxvglyw",
|
|
22
|
+
row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
|
|
23
|
+
};
|
|
20
24
|
var leftSurfaceRowStyles = null;
|
|
21
25
|
|
|
22
26
|
// Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
|
|
@@ -24,23 +28,24 @@ var leftSurfaceRowStyles = null;
|
|
|
24
28
|
// can stick near the top of the viewport instead of scrolling off with the node's top edge.
|
|
25
29
|
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
|
|
26
30
|
var leftSurfaceStickyStyles = null;
|
|
27
|
-
|
|
28
|
-
var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
|
|
31
|
+
var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_ref) {
|
|
29
32
|
var api = _ref.api,
|
|
30
33
|
components = _ref.components,
|
|
31
34
|
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
32
35
|
placement = _ref.placement,
|
|
33
36
|
source = _ref.source,
|
|
34
37
|
surfaceContext = _ref.surfaceContext;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
var blockControlsContext = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
39
|
+
var controlSide = (0, _blockControlsSurfaceContext.getBlockControlsSurfaceControlSide)(blockControlsContext, (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_controls_reliable_anchor'));
|
|
40
|
+
var _useBlockControlsVisi = (0, _visibilityContainer.useBlockControlsVisibility)({
|
|
41
|
+
api: api,
|
|
42
|
+
controlSide: controlSide,
|
|
43
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut
|
|
44
|
+
}),
|
|
45
|
+
shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
|
|
46
|
+
useCssStyles = _useBlockControlsVisi.useCssStyles;
|
|
43
47
|
var isSticky = placement.isSticky;
|
|
48
|
+
var isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
|
|
44
49
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
45
50
|
"data-editor-block-controls-surface": true,
|
|
46
51
|
"data-editor-block-controls-side": "left",
|
|
@@ -48,27 +53,36 @@ var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function Block
|
|
|
48
53
|
// 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.
|
|
49
54
|
,
|
|
50
55
|
style: placement.style,
|
|
51
|
-
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
56
|
+
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
|
|
52
57
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
53
|
-
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
58
|
-
shouldUseDisplayContents: true
|
|
58
|
+
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc"])
|
|
59
|
+
}, /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceComponents.BlockControlsVisibilityProvider, {
|
|
60
|
+
shouldHideHoverControls: shouldHideHoverControls,
|
|
61
|
+
useCssStyles: useCssStyles
|
|
59
62
|
}, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
|
|
60
|
-
components:
|
|
63
|
+
components: components,
|
|
61
64
|
surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
|
|
62
65
|
surfaceContext: surfaceContext
|
|
63
|
-
}))
|
|
66
|
+
}))));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** Renders one left block-controls surface at a document position. */
|
|
70
|
+
var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref2) {
|
|
71
|
+
var api = _ref2.api,
|
|
72
|
+
components = _ref2.components,
|
|
73
|
+
forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
|
|
74
|
+
placement = _ref2.placement,
|
|
75
|
+
source = _ref2.source,
|
|
76
|
+
surfaceContext = _ref2.surfaceContext;
|
|
77
|
+
if (!placement) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return /*#__PURE__*/_react.default.createElement(BlockControlsLeftSurfaceContent, {
|
|
64
81
|
api: api,
|
|
65
|
-
|
|
82
|
+
components: components,
|
|
66
83
|
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
|
|
70
|
-
components: persistentComponents,
|
|
71
|
-
surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
|
|
84
|
+
placement: placement,
|
|
85
|
+
source: source,
|
|
72
86
|
surfaceContext: surfaceContext
|
|
73
|
-
})
|
|
87
|
+
});
|
|
74
88
|
};
|
|
@@ -18,14 +18,13 @@ var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys"
|
|
|
18
18
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
19
19
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
20
20
|
var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
|
|
21
|
-
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
22
21
|
var _decorationsCommon = require("../pm-plugins/decorations-common");
|
|
23
22
|
var _blockControlsLeftSurface = require("./block-controls-left-surface");
|
|
23
|
+
var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
|
|
24
24
|
var _blockControlsSurfaceContext = require("./block-controls-surface-context");
|
|
25
25
|
var _blockControlsSurfaceTargets = require("./block-controls-surface-targets");
|
|
26
26
|
var _getNodeContentElement = require("./utils/get-node-content-element");
|
|
27
27
|
var _getSurfacePlacement = require("./utils/get-surface-placement");
|
|
28
|
-
var _hasSurfaceControls = require("./utils/has-surface-controls");
|
|
29
28
|
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); }
|
|
30
29
|
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; } } }; }
|
|
31
30
|
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; } }
|
|
@@ -69,14 +68,20 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
69
68
|
return [];
|
|
70
69
|
}
|
|
71
70
|
var surfaceContext = (0, _createSurfaceContext.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, context);
|
|
72
|
-
|
|
71
|
+
var surfaceComponents = (0, _blockControlsSurfaceComponents.getBlockControlsLeftSurfaceComponents)(components, surfaceContext);
|
|
72
|
+
if (!surfaceComponents) {
|
|
73
73
|
return [];
|
|
74
74
|
}
|
|
75
75
|
// The cache supplies the same anchor names used by ProseMirror decorations.
|
|
76
76
|
var anchorName = (0, _styles.isCSSAnchorSupported)() ? surfaceAnchors.get(target.position) : undefined;
|
|
77
|
+
// Top-level controls can respond to the available left gutter without the surface
|
|
78
|
+
// host knowing which controls are registered or how they adapt.
|
|
79
|
+
var isTopLevel = context.targetNode.parentType === 'doc';
|
|
77
80
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
78
81
|
anchorName: anchorName,
|
|
79
82
|
blockControlsContext: context,
|
|
83
|
+
isTopLevel: isTopLevel,
|
|
84
|
+
surfaceComponents: surfaceComponents,
|
|
80
85
|
surfaceContext: surfaceContext
|
|
81
86
|
})];
|
|
82
87
|
});
|
|
@@ -89,15 +94,22 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
89
94
|
return new Map(surfaces.flatMap(function (_ref3) {
|
|
90
95
|
var anchorName = _ref3.anchorName,
|
|
91
96
|
blockControlsContext = _ref3.blockControlsContext,
|
|
97
|
+
isTopLevel = _ref3.isTopLevel,
|
|
92
98
|
position = _ref3.position;
|
|
93
|
-
|
|
99
|
+
if (!anchorName) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
var options = {
|
|
94
103
|
anchorName: anchorName,
|
|
104
|
+
layout: blockControlsContext.targetNode.node.attrs.layout,
|
|
95
105
|
nodeType: blockControlsContext.targetNode.type.name,
|
|
96
106
|
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
108
|
+
};
|
|
109
|
+
var placement = isTopLevel ? (0, _getSurfacePlacement.getAnchoredLeftGutterSurfacePlacement)(options) : (0, _getSurfacePlacement.getAnchoredSurfacePlacement)(_objectSpread(_objectSpread({}, options), {}, {
|
|
99
110
|
side: 'left'
|
|
100
|
-
})
|
|
111
|
+
}));
|
|
112
|
+
return [[position, placement]];
|
|
101
113
|
}));
|
|
102
114
|
}, [surfaces]);
|
|
103
115
|
// Only the surfaces that still need measuring drive the effect below, so a document of anchored
|
|
@@ -131,6 +143,7 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
131
143
|
}
|
|
132
144
|
var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
|
|
133
145
|
var blockControlsContext = _ref5.blockControlsContext,
|
|
146
|
+
isTopLevel = _ref5.isTopLevel,
|
|
134
147
|
position = _ref5.position;
|
|
135
148
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
136
149
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
@@ -139,6 +152,7 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
139
152
|
}
|
|
140
153
|
return [{
|
|
141
154
|
blockControlsContext: blockControlsContext,
|
|
155
|
+
isTopLevel: isTopLevel,
|
|
142
156
|
position: position,
|
|
143
157
|
targetElement: (0, _getNodeContentElement.getNodeContentElement)(targetElementRoot, blockControlsContext.targetNode.type.name),
|
|
144
158
|
targetElementRoot: targetElementRoot
|
|
@@ -158,23 +172,28 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
158
172
|
_step;
|
|
159
173
|
try {
|
|
160
174
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
161
|
-
var _targetElementRoot$ge;
|
|
175
|
+
var _targetElementRoot$ge, _offsetParentRect$lef;
|
|
162
176
|
var _step$value = _step.value,
|
|
163
177
|
blockControlsContext = _step$value.blockControlsContext,
|
|
178
|
+
isTopLevel = _step$value.isTopLevel,
|
|
164
179
|
position = _step$value.position,
|
|
165
180
|
targetElement = _step$value.targetElement,
|
|
166
181
|
targetElementRoot = _step$value.targetElementRoot;
|
|
167
182
|
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
168
183
|
continue;
|
|
169
184
|
}
|
|
170
|
-
var
|
|
185
|
+
var options = {
|
|
171
186
|
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
172
187
|
nodeRect: targetElement.getBoundingClientRect(),
|
|
173
188
|
nodeType: blockControlsContext.targetNode.type.name,
|
|
174
189
|
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
175
|
-
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
190
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
191
|
+
};
|
|
192
|
+
var placement = isTopLevel ? (0, _getSurfacePlacement.getLeftGutterSurfacePlacement)(_objectSpread(_objectSpread({}, options), {}, {
|
|
193
|
+
leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
|
|
194
|
+
})) : (0, _getSurfacePlacement.getSurfacePlacement)(_objectSpread(_objectSpread({}, options), {}, {
|
|
176
195
|
side: 'left'
|
|
177
|
-
});
|
|
196
|
+
}));
|
|
178
197
|
nextPlacements.set(position, (0, _getSurfacePlacement.toMeasuredSurfaceWrapperPlacement)((0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
179
198
|
offsetParentRect: offsetParentRect,
|
|
180
199
|
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
@@ -260,10 +279,11 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
260
279
|
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
261
280
|
var position = _ref6.position,
|
|
262
281
|
source = _ref6.source,
|
|
282
|
+
surfaceComponents = _ref6.surfaceComponents,
|
|
263
283
|
surfaceContext = _ref6.surfaceContext;
|
|
264
284
|
return /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurface.BlockControlsLeftSurface, {
|
|
265
285
|
api: api,
|
|
266
|
-
components:
|
|
286
|
+
components: surfaceComponents,
|
|
267
287
|
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
268
288
|
key: position,
|
|
269
289
|
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
@@ -11,7 +11,7 @@ var _runtime = require("@compiled/react/runtime");
|
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
12
12
|
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
13
13
|
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
14
|
-
var
|
|
14
|
+
var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
|
|
15
15
|
var _visibilityContainer = require("./visibility-container");
|
|
16
16
|
var rightSurfaceOuterStyles = null;
|
|
17
17
|
var rightSurfaceRowStyles = null;
|
|
@@ -21,22 +21,20 @@ var rightSurfaceRowStyles = null;
|
|
|
21
21
|
// can stick near the top of the viewport instead of scrolling off with the node's top edge.
|
|
22
22
|
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
|
|
23
23
|
var rightSurfaceStickyStyles = null;
|
|
24
|
-
|
|
25
|
-
var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref) {
|
|
24
|
+
var BlockControlsRightSurfaceContent = function BlockControlsRightSurfaceContent(_ref) {
|
|
26
25
|
var api = _ref.api,
|
|
27
26
|
components = _ref.components,
|
|
28
27
|
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
29
28
|
placement = _ref.placement,
|
|
30
29
|
source = _ref.source,
|
|
31
30
|
surfaceContext = _ref.surfaceContext;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var willRenderHoverOnly = (0, _surfaceRenderer.willSurfaceRender)(hoverOnlyComponents, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
|
|
31
|
+
var _useBlockControlsVisi = (0, _visibilityContainer.useBlockControlsVisibility)({
|
|
32
|
+
api: api,
|
|
33
|
+
controlSide: 'right',
|
|
34
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut
|
|
35
|
+
}),
|
|
36
|
+
shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
|
|
37
|
+
useCssStyles = _useBlockControlsVisi.useCssStyles;
|
|
40
38
|
var isSticky = placement.isSticky;
|
|
41
39
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
42
40
|
"data-editor-block-controls-surface": true,
|
|
@@ -48,23 +46,33 @@ var BlockControlsRightSurface = exports.BlockControlsRightSurface = function Blo
|
|
|
48
46
|
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
49
47
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
50
48
|
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
isPersistent: true,
|
|
55
|
-
shouldUseDisplayContents: true
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceComponents.BlockControlsVisibilityProvider, {
|
|
50
|
+
shouldHideHoverControls: shouldHideHoverControls,
|
|
51
|
+
useCssStyles: useCssStyles
|
|
56
52
|
}, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
|
|
57
|
-
components:
|
|
53
|
+
components: components,
|
|
58
54
|
surface: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE,
|
|
59
55
|
surfaceContext: surfaceContext
|
|
60
|
-
}))
|
|
56
|
+
}))));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Renders one right block-controls surface at a document position. */
|
|
60
|
+
var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref2) {
|
|
61
|
+
var api = _ref2.api,
|
|
62
|
+
components = _ref2.components,
|
|
63
|
+
forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
|
|
64
|
+
placement = _ref2.placement,
|
|
65
|
+
source = _ref2.source,
|
|
66
|
+
surfaceContext = _ref2.surfaceContext;
|
|
67
|
+
if (!placement) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return /*#__PURE__*/_react.default.createElement(BlockControlsRightSurfaceContent, {
|
|
61
71
|
api: api,
|
|
62
|
-
|
|
72
|
+
components: components,
|
|
63
73
|
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
components: hoverOnlyComponents,
|
|
67
|
-
surface: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE,
|
|
74
|
+
placement: placement,
|
|
75
|
+
source: source,
|
|
68
76
|
surfaceContext: surfaceContext
|
|
69
|
-
})
|
|
77
|
+
});
|
|
70
78
|
};
|
|
@@ -18,14 +18,13 @@ var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys"
|
|
|
18
18
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
19
19
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
20
20
|
var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
|
|
21
|
-
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
22
21
|
var _decorationsCommon = require("../pm-plugins/decorations-common");
|
|
23
22
|
var _blockControlsRightSurface = require("./block-controls-right-surface");
|
|
23
|
+
var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
|
|
24
24
|
var _blockControlsSurfaceContext = require("./block-controls-surface-context");
|
|
25
25
|
var _blockControlsSurfaceTargets = require("./block-controls-surface-targets");
|
|
26
26
|
var _getNodeContentElement = require("./utils/get-node-content-element");
|
|
27
27
|
var _getSurfacePlacement = require("./utils/get-surface-placement");
|
|
28
|
-
var _hasSurfaceControls = require("./utils/has-surface-controls");
|
|
29
28
|
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); }
|
|
30
29
|
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; } } }; }
|
|
31
30
|
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; } }
|
|
@@ -78,7 +77,8 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
78
77
|
return [];
|
|
79
78
|
}
|
|
80
79
|
var surfaceContext = (0, _createSurfaceContext.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, context);
|
|
81
|
-
|
|
80
|
+
var surfaceComponents = (0, _blockControlsSurfaceComponents.getBlockControlsRightSurfaceComponents)(components, surfaceContext);
|
|
81
|
+
if (!surfaceComponents) {
|
|
82
82
|
return [];
|
|
83
83
|
}
|
|
84
84
|
// The cache supplies the same anchor names used by ProseMirror decorations.
|
|
@@ -86,6 +86,7 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
86
86
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
87
87
|
anchorName: anchorName,
|
|
88
88
|
blockControlsContext: context,
|
|
89
|
+
surfaceComponents: surfaceComponents,
|
|
89
90
|
surfaceContext: surfaceContext
|
|
90
91
|
})];
|
|
91
92
|
});
|
|
@@ -269,10 +270,11 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
269
270
|
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
270
271
|
var position = _ref6.position,
|
|
271
272
|
source = _ref6.source,
|
|
273
|
+
surfaceComponents = _ref6.surfaceComponents,
|
|
272
274
|
surfaceContext = _ref6.surfaceContext;
|
|
273
275
|
return /*#__PURE__*/_react.default.createElement(_blockControlsRightSurface.BlockControlsRightSurface, {
|
|
274
276
|
api: api,
|
|
275
|
-
components:
|
|
277
|
+
components: surfaceComponents,
|
|
276
278
|
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
277
279
|
key: position,
|
|
278
280
|
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
@@ -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
|
+
};
|