diff --git a/app/client/src/layoutSystems/anvil/integrations/layoutSelectors.ts b/app/client/src/layoutSystems/anvil/integrations/layoutSelectors.ts deleted file mode 100644 index c4ad61945bc..00000000000 --- a/app/client/src/layoutSystems/anvil/integrations/layoutSelectors.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getLayoutElementPositions } from "layoutSystems/common/selectors"; -import type { - LayoutElementPosition, - LayoutElementPositions, -} from "layoutSystems/common/types"; -import { createSelector } from "reselect"; -import { AlignmentIndexMap } from "../utils/constants"; -import { FlexLayerAlignment } from "layoutSystems/common/utils/constants"; - -export const ALIGNMENT_WIDTH_THRESHOLD = 0.95; - -export function shouldOverrideAlignmentStyle(layoutId: string) { - return createSelector( - getLayoutElementPositions, - (positions: LayoutElementPositions): boolean => { - if (!layoutId || !positions || !positions[layoutId]) return false; - - // If positions don't exist for start alignment, return false as this layout is not aligned. - if (!positions[`${layoutId}-0`]) return false; - - const layoutPosition: LayoutElementPosition = positions[layoutId]; - const threshold = layoutPosition.width * ALIGNMENT_WIDTH_THRESHOLD; - - // return true if width of any alignment exceeds the limit. - return [ - FlexLayerAlignment.Start, - FlexLayerAlignment.Center, - FlexLayerAlignment.End, - ].some((each: FlexLayerAlignment) => { - const alignmentPosition: LayoutElementPosition = - positions[`${layoutId}-${AlignmentIndexMap[each]}`]; - return alignmentPosition.width >= threshold; - }); - }, - ); -} diff --git a/app/client/src/layoutSystems/anvil/layoutComponents/components/FlexLayout.tsx b/app/client/src/layoutSystems/anvil/layoutComponents/components/FlexLayout.tsx index 44ad6a6fd01..0725d15729d 100644 --- a/app/client/src/layoutSystems/anvil/layoutComponents/components/FlexLayout.tsx +++ b/app/client/src/layoutSystems/anvil/layoutComponents/components/FlexLayout.tsx @@ -1,21 +1,9 @@ import "./styles.css"; import { Flex } from "@design-system/widgets"; -import type { - AlignSelf, - FlexDirection, - FlexProps, - FlexWrap, - JustifyContent, - Responsive, - SizingDimension, - SpacingDimension, -} from "@design-system/widgets"; +import type { FlexProps } from "@design-system/widgets"; import React, { useMemo } from "react"; import type { CSSProperties, ReactNode } from "react"; -import type { - OverflowValues, - PositionValues, -} from "layoutSystems/anvil/utils/types"; +import type { PositionValues } from "layoutSystems/anvil/utils/types"; import { usePositionObserver } from "layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver"; import { getAnvilLayoutDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils"; import type { RenderMode } from "constants/WidgetConstants"; @@ -26,11 +14,7 @@ import { getShouldHighLightCellSelector, } from "layoutSystems/anvil/integrations/selectors"; -export interface FlexLayoutProps - extends AlignSelf, - JustifyContent, - FlexDirection, - FlexWrap { +export interface FlexLayoutProps extends FlexProps { canvasId: string; children: ReactNode; isContainer?: boolean; @@ -39,35 +23,16 @@ export interface FlexLayoutProps layoutIndex: number; layoutType: LayoutComponentTypes; parentDropTarget: string; - renderMode: RenderMode; - - border?: string; - columnGap?: Responsive; - flexBasis?: Responsive; - flexGrow?: Responsive; - flexShrink?: Responsive; - height?: Responsive; - maxHeight?: Responsive; - maxWidth?: Responsive; - minWidth?: Responsive; - minHeight?: Responsive; - overflowX?: OverflowValues; - overflowY?: OverflowValues; position?: PositionValues; - gap?: Responsive; - padding?: Responsive; - width?: Responsive; - className?: string; + renderMode: RenderMode; } export const FlexLayout = React.memo((props: FlexLayoutProps) => { const { alignSelf, - border, canvasId, children, className, - columnGap, direction, flexBasis, flexGrow, @@ -87,9 +52,9 @@ export const FlexLayout = React.memo((props: FlexLayoutProps) => { padding, parentDropTarget, position, - renderMode, width, wrap, + ...rest } = props; /** POSITIONS OBSERVER LOGIC */ // Create a ref so that this DOM node can be @@ -111,7 +76,6 @@ export const FlexLayout = React.memo((props: FlexLayoutProps) => { const flexProps: FlexProps = useMemo(() => { return { alignSelf: alignSelf || "flex-start", - columnGap: columnGap || "0px", direction: direction || "column", flexBasis: flexBasis || "auto", flexGrow: flexGrow || 0, @@ -130,7 +94,6 @@ export const FlexLayout = React.memo((props: FlexLayoutProps) => { }; }, [ alignSelf, - columnGap, direction, flexBasis, flexGrow, @@ -160,7 +123,7 @@ export const FlexLayout = React.memo((props: FlexLayoutProps) => { ? { background: "var(--anvil-cell-highlight)" } : {}), }; - }, [border, isDropTarget, position, renderMode, shouldHighlightCell]); + }, [isDropTarget, position, shouldHighlightCell]); const _className = useMemo(() => { return `${className ?? ""} layout-${layoutId} layout-index-${layoutIndex} ${ @@ -171,6 +134,7 @@ export const FlexLayout = React.memo((props: FlexLayoutProps) => { return ( { const { canvasId, layout, layoutId, renderMode } = props; - // Whether default alignment styles should be overridden, when renderMode = Canvas. - const shouldOverrideStyle: boolean = useSelector( - shouldOverrideAlignmentStyle(layoutId), - ); - - // check if layout renders a Fill widget. - const hasFillWidget: boolean = isFillWidgetPresentInList( - layout as WidgetLayoutProps[], - ); - - const [isAnyAlignmentOverflowing, setIsAnyAlignmentOverflowing] = - useState(false); - - useEffect(() => { - // getBoundingClientRect is an expensive operation and should only be used when renderMode = Page, - // because layout positions are not available in that case. - if (hasFillWidget || renderMode !== RenderModes.PAGE) return; - const parentLayoutId = getAnvilLayoutDOMId(canvasId, layoutId); - const parentLayout = document.getElementById(parentLayoutId); - if (parentLayout) { - const parentLayoutWidth = parentLayout.getBoundingClientRect().width; - - // Use requestAnimationFrame to ensure calculation is done after rendering - requestAnimationFrame(() => { - const isOverflowing = [ - FlexLayerAlignment.Start, - FlexLayerAlignment.Center, - FlexLayerAlignment.End, - ].some((each: FlexLayerAlignment) => { - const alignmentId = `${parentLayoutId}-${AlignmentIndexMap[each]}`; - const alignment = document.getElementById(alignmentId); - if (!alignment) return false; - const alignmentWidth = alignment.getBoundingClientRect().width; - // return true if width of any alignment exceeds the limit. - return ( - alignmentWidth >= parentLayoutWidth * ALIGNMENT_WIDTH_THRESHOLD - ); - }); - setIsAnyAlignmentOverflowing(isOverflowing); - }); - } - }, [hasFillWidget, layout.length, renderMode]); - - useEffect(() => { - if (hasFillWidget || renderMode === RenderModes.PAGE) return; - setIsAnyAlignmentOverflowing(shouldOverrideStyle); - }, [hasFillWidget, renderMode, shouldOverrideStyle]); - - const isEditMode = useSelector(isEditOnlyModeSelector); - const isStartVisible = () => startChildren.length > 0 || isEditMode; - const isCenterVisible = () => centerChildren.length > 0 || isEditMode; - const isEndVisible = () => endChildren.length > 0 || isEditMode; const commonProps: Omit< FlexLayoutProps, @@ -106,21 +44,22 @@ const AlignedWidgetRowComp = (props: LayoutComponentProps) => { alignSelf: "stretch", canvasId, direction: "row", - flexBasis: isAnyAlignmentOverflowing - ? { base: "auto" } - : { base: "auto", [`${MOBILE_BREAKPOINT}px`]: "0%" }, + flexBasis: "0%", flexGrow: 1, flexShrink: 1, layoutType: LayoutComponentTypes.WIDGET_ROW, parentDropTarget: props.parentDropTarget, - renderMode: props.renderMode, - wrap: isAnyAlignmentOverflowing - ? { base: "wrap" } - : { base: "wrap", [`${MOBILE_BREAKPOINT}px`]: "nowrap" }, + renderMode, + wrap: { base: "wrap", [`${MOBILE_BREAKPOINT}px`]: "nowrap" }, className: props.className, maxWidth: "100%", }; - }, [isAnyAlignmentOverflowing]); + }, []); + + // check if layout renders a Fill widget. + const hasFillWidget: boolean = isFillWidgetPresentInList( + layout as WidgetLayoutProps[], + ); // If a Fill widget exists, then render the child widgets together. if (hasFillWidget) { @@ -152,54 +91,48 @@ const AlignedWidgetRowComp = (props: LayoutComponentProps) => { // WDS Flex can be used as a replacement. return ( <> - {isStartVisible() && ( - - {renderWidgets({ + + {renderWidgets({ + ...props, + layout: startChildren, + })} + + + {renderWidgets( + { + ...props, + layout: centerChildren, + }, + startChildren?.length, + )} + + + {renderWidgets( + { ...props, - layout: startChildren, - })} - - )} - {isCenterVisible() && ( - - {renderWidgets( - { - ...props, - layout: centerChildren, - }, - startChildren?.length, - )} - - )} - {isEndVisible() && ( - - {renderWidgets( - { - ...props, - layout: endChildren, - }, - startChildren?.length + centerChildren?.length, - )} - - )} + layout: endChildren, + }, + startChildren?.length + centerChildren?.length, + )} + ); }; diff --git a/app/client/src/layoutSystems/anvil/utils/anvilTypes.ts b/app/client/src/layoutSystems/anvil/utils/anvilTypes.ts index 741fb80cf62..0180ceb3676 100644 --- a/app/client/src/layoutSystems/anvil/utils/anvilTypes.ts +++ b/app/client/src/layoutSystems/anvil/utils/anvilTypes.ts @@ -140,19 +140,6 @@ export interface DraggedWidget { widgetId: string; } -export type GenerateHighlights = ( - baseHighlight: AnvilHighlightInfo, - layoutDimension: LayoutElementPosition, - currentDimension: LayoutElementPosition, - prevDimension: LayoutElementPosition | undefined, - nextDimension: LayoutElementPosition | undefined, - rowIndex: number, - isLastHighlight: boolean, - prevHighlight: AnvilHighlightInfo | undefined, - hasFillWidget?: boolean, - isDropTarget?: boolean, -) => AnvilHighlightInfo[]; - export type GetInitialHighlights = ( layoutProps: LayoutProps, baseHighlight: AnvilHighlightInfo, @@ -202,14 +189,3 @@ export interface HighlightPayload { highlights: AnvilHighlightInfo[]; skipEntity: boolean; } - -export type UpdateHighlights = ( - arr: AnvilHighlightInfo[], - baseHighlight: AnvilHighlightInfo, - layoutDimension: LayoutElementPosition, - currDimension: LayoutElementPosition, - nextDimension: LayoutElementPosition | undefined, - rowIndex: number, - isLastHighlight: boolean, - hasFillWidget?: boolean, -) => AnvilHighlightInfo[];