@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
111 lines (108 loc) • 6.01 kB
JavaScript
/* block-controls-right-surface.tsx generated by @compiled/babel-plugin v3.0.2 */
import "./block-controls-right-surface.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
import { BlockControlsSurfaceWithClsFix } from '../surface-lifecycle/block-controls-surface-with-cls-fix';
import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
import { useBlockControlsVisibility } from './visibility-container';
var rightSurfaceHiddenWrapperStyles = null;
var rightSurfaceOuterStyles = null;
var rightSurfaceRowStyles = null;
// Applied in addition to rightSurfaceRowStyles when the target node is sticky-eligible (e.g. long
// tables): the outer wrapper spans the node's full height (see `placement.height`), so the content
// can stick near the top of the viewport instead of scrolling off with the node's top edge.
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
var rightSurfaceStickyStyles = null;
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER in ./consts (must be a static literal here)
var rightSurfaceStickyTableHeaderStyles = null;
var BlockControlsRightSurfaceContent = function BlockControlsRightSurfaceContent(_ref) {
var api = _ref.api,
components = _ref.components,
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
placement = _ref.placement,
source = _ref.source,
surfaceContext = _ref.surfaceContext;
var blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
var _useBlockControlsVisi = useBlockControlsVisibility({
api: api,
controlSide: 'right',
forceVisibleOnMouseOut: forceVisibleOnMouseOut
}),
shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
useCssStyles = _useBlockControlsVisi.useCssStyles;
var isSticky = placement.isSticky;
return /*#__PURE__*/React.createElement("div", {
"data-editor-block-controls-surface": true,
"data-editor-block-controls-side": "right",
"data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
// 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.
,
style: placement.style,
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
}, /*#__PURE__*/React.createElement("div", {
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
}, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
shouldHideHoverControls: shouldHideHoverControls,
useCssStyles: useCssStyles
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
components: components,
surface: BLOCK_CONTROLS_RIGHT_SURFACE,
surfaceContext: surfaceContext
}))));
};
var BlockControlsRightSurfaceWrapper = function BlockControlsRightSurfaceWrapper(_ref2) {
var children = _ref2.children,
placement = _ref2.placement,
source = _ref2.source,
surfaceContext = _ref2.surfaceContext;
var blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
var isSticky = placement.isSticky;
return /*#__PURE__*/React.createElement("div", {
"data-editor-block-controls-surface": true,
"data-editor-block-controls-side": "right",
"data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
// 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.
,
style: placement.style,
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", "_3um015vq"])
}, /*#__PURE__*/React.createElement("div", {
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
}, children));
};
/** Renders one right block-controls surface at a document position. */
export var BlockControlsRightSurface = function BlockControlsRightSurface(_ref3) {
var api = _ref3.api,
components = _ref3.components,
forceVisibleOnMouseOut = _ref3.forceVisibleOnMouseOut,
placement = _ref3.placement,
source = _ref3.source,
surfaceContext = _ref3.surfaceContext;
if (!placement) {
return null;
}
if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
return /*#__PURE__*/React.createElement(BlockControlsSurfaceWithClsFix, {
side: "right",
SurfaceWrapper: BlockControlsRightSurfaceWrapper,
api: api,
components: components,
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
placement: placement,
source: source,
surfaceContext: surfaceContext
});
} else {
return /*#__PURE__*/React.createElement(BlockControlsRightSurfaceContent, {
api: api,
components: components,
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
placement: placement,
source: source,
surfaceContext: surfaceContext
});
}
};