UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

129 lines (125 loc) • 7.59 kB
/* 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'; var leftSurfaceHiddenWrapperStyles = null; var leftSurfaceOuterStyles = null; var 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. var nestedSurfacePointerEventsStyles = { container: "_lcxvglyw", row: "_lcxvglyw _w1y61wug" }; var 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). var leftSurfaceStickyStyles = null; // Keep in sync with STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER in ./consts (must be a static literal here) var leftSurfaceStickyTableHeaderStyles = null; var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_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 controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor')); var _useBlockControlsVisi = useBlockControlsVisibility({ api: api, controlSide: controlSide, forceVisibleOnMouseOut: forceVisibleOnMouseOut }), shouldHideHoverControls = _useBlockControlsVisi.shouldHide, useCssStyles = _useBlockControlsVisi.useCssStyles; var isSticky = placement.isSticky; var isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc'; var 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 })))); }; var BlockControlsLeftSurfaceWrapper = function BlockControlsLeftSurfaceWrapper(_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; var 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 var BlockControlsLeftSurface = function BlockControlsLeftSurface(_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: "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 }); } };