@atlaskit/editor-plugin-block-controls
Version:
Block controls plugin for @atlaskit/editor-core
133 lines (129 loc) • 7.05 kB
JavaScript
/* block-controls-left-surface.tsx generated by @compiled/babel-plugin v3.0.2 */
import "./block-controls-left-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_LEFT_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 { getBlockControlsSurfaceControlSide } from './block-controls-surface-context';
import { useBlockControlsVisibility } from './visibility-container';
const leftSurfaceHiddenWrapperStyles = null;
const leftSurfaceOuterStyles = null;
const leftSurfaceGutterStyles = {
container: "_1f38ffwv _7cca15wb _lcxvglyw",
row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
};
// Nested surfaces (e.g. a table inside an expand) can span the target node's full height and sit
// over controls rendered in the node's own gutter, such as the table row insert button. Let pointer
// events pass through the wrapper and row so those controls stay interactive, matching the top-level
// gutter behaviour without applying its container query sizing.
const nestedSurfacePointerEventsStyles = {
container: "_lcxvglyw",
row: "_lcxvglyw _w1y61wug"
};
const leftSurfaceRowStyles = null;
// Applied in addition to leftSurfaceRowStyles 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).
const leftSurfaceStickyStyles = null;
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER in ./consts (must be a static literal here)
const leftSurfaceStickyTableHeaderStyles = null;
const BlockControlsLeftSurfaceContent = ({
api,
components,
forceVisibleOnMouseOut,
placement,
source,
surfaceContext
}) => {
const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
const controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor'));
const {
shouldHide: shouldHideHoverControls,
useCssStyles
} = useBlockControlsVisibility({
api,
controlSide,
forceVisibleOnMouseOut
});
const isSticky = placement.isSticky;
const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
const shouldPassThroughNestedPointerEvents = !isTopLevel && isExperimentEnabled('platform_editor_nested_left_surface_pointer_fix');
return /*#__PURE__*/React.createElement("div", {
"data-editor-block-controls-surface": true,
"data-editor-block-controls-side": "left",
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-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", isTopLevel && leftSurfaceGutterStyles.container, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.container])
}, /*#__PURE__*/React.createElement("div", {
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.row, 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_LEFT_SURFACE,
surfaceContext: surfaceContext
}))));
};
const BlockControlsLeftSurfaceWrapper = ({
children,
placement,
source,
surfaceContext
}) => {
const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
const isSticky = placement.isSticky;
const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
return /*#__PURE__*/React.createElement("div", {
"data-editor-block-controls-surface": true,
"data-editor-block-controls-side": "left",
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-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", isTopLevel && leftSurfaceGutterStyles.container, "_3um015vq"])
}, /*#__PURE__*/React.createElement("div", {
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, 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 left block-controls surface at a document position. */
export const BlockControlsLeftSurface = ({
api,
components,
forceVisibleOnMouseOut,
placement,
source,
surfaceContext
}) => {
if (!placement) {
return null;
}
if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
return /*#__PURE__*/React.createElement(BlockControlsSurfaceWithClsFix, {
side: "left",
SurfaceWrapper: BlockControlsLeftSurfaceWrapper,
api: api,
components: components,
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
placement: placement,
source: source,
surfaceContext: surfaceContext
});
} else {
return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
api: api,
components: components,
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
placement: placement,
source: source,
surfaceContext: surfaceContext
});
}
};