2023-03-04 07:25:54 +00:00
|
|
|
import log from "loglevel";
|
|
|
|
|
import React from "react";
|
2022-05-04 09:45:57 +00:00
|
|
|
import styled from "styled-components";
|
2023-07-26 12:40:44 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
|
|
|
|
import { useSelector } from "react-redux";
|
2023-09-06 12:15:04 +00:00
|
|
|
import type { CanvasWidgetStructure } from "WidgetProvider/constants";
|
2022-12-30 14:52:11 +00:00
|
|
|
import useWidgetFocus from "utils/hooks/useWidgetFocus";
|
2023-07-26 12:40:44 +00:00
|
|
|
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
|
2023-11-03 17:13:36 +00:00
|
|
|
import { combinedPreviewModeSelector } from "selectors/editorSelectors";
|
2023-07-26 12:40:44 +00:00
|
|
|
import { getSelectedAppTheme } from "selectors/appThemingSelectors";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { getViewportClassName } from "layoutSystems/autolayout/utils/AutoLayoutUtils";
|
2023-09-15 17:00:10 +00:00
|
|
|
import type { FontFamily } from "@design-system/theming";
|
2023-07-26 12:40:44 +00:00
|
|
|
import {
|
|
|
|
|
ThemeProvider as WDSThemeProvider,
|
|
|
|
|
useTheme,
|
|
|
|
|
} from "@design-system/theming";
|
2023-03-23 11:41:58 +00:00
|
|
|
import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors";
|
2023-10-06 10:07:43 +00:00
|
|
|
import { CANVAS_ART_BOARD } from "constants/componentClassNameConstants";
|
2023-10-04 11:53:29 +00:00
|
|
|
import { renderAppsmithCanvas } from "layoutSystems/CanvasFactory";
|
|
|
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
2023-10-20 03:00:46 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2023-12-01 12:39:21 +00:00
|
|
|
import { getAppThemeSettings } from "@appsmith/selectors/applicationSelectors";
|
2019-03-21 17:42:23 +00:00
|
|
|
|
2019-08-26 12:41:21 +00:00
|
|
|
interface CanvasProps {
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetsStructure: CanvasWidgetStructure;
|
2021-08-18 10:29:52 +00:00
|
|
|
pageId: string;
|
2022-08-19 10:10:36 +00:00
|
|
|
canvasWidth: number;
|
2023-09-12 14:14:02 +00:00
|
|
|
enableMainCanvasResizer?: boolean;
|
2019-08-29 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-12 14:14:02 +00:00
|
|
|
const Wrapper = styled.section<{
|
2022-05-04 09:45:57 +00:00
|
|
|
background: string;
|
2023-02-03 05:47:40 +00:00
|
|
|
width: number;
|
2023-09-12 14:14:02 +00:00
|
|
|
$enableMainCanvasResizer: boolean;
|
2022-05-04 09:45:57 +00:00
|
|
|
}>`
|
|
|
|
|
background: ${({ background }) => background};
|
2023-09-12 14:14:02 +00:00
|
|
|
width: ${({ $enableMainCanvasResizer, width }) =>
|
|
|
|
|
$enableMainCanvasResizer ? `100%` : `${width}px`};
|
2022-05-04 09:45:57 +00:00
|
|
|
`;
|
2023-02-03 05:47:40 +00:00
|
|
|
const Canvas = (props: CanvasProps) => {
|
2023-02-17 08:42:54 +00:00
|
|
|
const { canvasWidth } = props;
|
2023-11-03 17:13:36 +00:00
|
|
|
const isPreviewMode = useSelector(combinedPreviewModeSelector);
|
2023-03-23 11:41:58 +00:00
|
|
|
const isAppSettingsPaneWithNavigationTabOpen = useSelector(
|
|
|
|
|
getIsAppSettingsPaneWithNavigationTabOpen,
|
|
|
|
|
);
|
2022-05-04 09:45:57 +00:00
|
|
|
const selectedTheme = useSelector(getSelectedAppTheme);
|
2023-12-01 12:39:21 +00:00
|
|
|
const isWDSEnabled = useFeatureFlag("ab_wds_enabled");
|
2023-10-20 03:00:46 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes = useSelector(getLayoutSystemType);
|
2023-09-15 17:00:10 +00:00
|
|
|
|
2023-12-01 12:39:21 +00:00
|
|
|
const themeSetting = useSelector(getAppThemeSettings);
|
|
|
|
|
const themeProps = {
|
2023-07-26 12:40:44 +00:00
|
|
|
borderRadius: selectedTheme.properties.borderRadius.appBorderRadius,
|
|
|
|
|
seedColor: selectedTheme.properties.colors.primaryColor,
|
2023-09-15 17:00:10 +00:00
|
|
|
fontFamily: selectedTheme.properties.fontFamily.appFont as FontFamily,
|
2023-12-01 12:39:21 +00:00
|
|
|
};
|
|
|
|
|
const wdsThemeProps = {
|
|
|
|
|
borderRadius: themeSetting.borderRadius,
|
|
|
|
|
seedColor: themeSetting.accentColor,
|
2023-12-28 08:28:33 +00:00
|
|
|
colorMode: themeSetting.colorMode.toLowerCase(),
|
2023-12-01 12:39:21 +00:00
|
|
|
fontFamily: themeSetting.fontFamily as FontFamily,
|
|
|
|
|
userSizing: themeSetting.sizing,
|
|
|
|
|
userDensity: themeSetting.density,
|
|
|
|
|
};
|
|
|
|
|
const { theme } = useTheme(isWDSEnabled ? wdsThemeProps : themeProps);
|
2022-05-04 09:45:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* background for canvas
|
|
|
|
|
*/
|
2023-12-18 11:16:00 +00:00
|
|
|
let backgroundForCanvas: string;
|
2022-05-04 09:45:57 +00:00
|
|
|
|
2023-03-23 11:41:58 +00:00
|
|
|
if (isPreviewMode || isAppSettingsPaneWithNavigationTabOpen) {
|
2023-12-18 11:16:00 +00:00
|
|
|
backgroundForCanvas = "initial";
|
2022-05-04 09:45:57 +00:00
|
|
|
} else {
|
2023-12-18 11:16:00 +00:00
|
|
|
backgroundForCanvas = selectedTheme.properties.colors.backgroundColor;
|
2022-05-04 09:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 14:52:11 +00:00
|
|
|
const focusRef = useWidgetFocus();
|
|
|
|
|
|
2023-09-12 14:14:02 +00:00
|
|
|
const marginHorizontalClass = props.enableMainCanvasResizer
|
|
|
|
|
? `mx-0`
|
|
|
|
|
: `mx-auto`;
|
|
|
|
|
const paddingBottomClass = props.enableMainCanvasResizer ? "" : "pb-52";
|
2023-12-18 11:16:00 +00:00
|
|
|
|
2024-01-02 19:47:56 +00:00
|
|
|
const height = layoutSystemType === LayoutSystemTypes.ANVIL ? "h-full" : "";
|
|
|
|
|
|
2023-12-18 11:16:00 +00:00
|
|
|
const renderChildren = () => {
|
2019-11-26 10:45:46 +00:00
|
|
|
return (
|
2023-12-18 11:16:00 +00:00
|
|
|
<Wrapper
|
|
|
|
|
$enableMainCanvasResizer={!!props.enableMainCanvasResizer}
|
|
|
|
|
background={isWDSEnabled ? "" : backgroundForCanvas}
|
2024-01-02 19:47:56 +00:00
|
|
|
className={`relative t--canvas-artboard ${height} ${paddingBottomClass} transition-all duration-400 ${marginHorizontalClass} ${getViewportClassName(
|
2023-12-18 11:16:00 +00:00
|
|
|
canvasWidth,
|
|
|
|
|
)}`}
|
|
|
|
|
data-testid={"t--canvas-artboard"}
|
|
|
|
|
id={CANVAS_ART_BOARD}
|
|
|
|
|
ref={isWDSEnabled ? undefined : focusRef}
|
|
|
|
|
width={canvasWidth}
|
|
|
|
|
>
|
|
|
|
|
{props.widgetsStructure.widgetId &&
|
|
|
|
|
renderAppsmithCanvas({
|
|
|
|
|
...props.widgetsStructure,
|
|
|
|
|
classList:
|
|
|
|
|
layoutSystemType === LayoutSystemTypes.ANVIL
|
|
|
|
|
? ["main-anvil-canvas"]
|
|
|
|
|
: [],
|
|
|
|
|
} as WidgetProps)}
|
|
|
|
|
</Wrapper>
|
2019-11-26 10:45:46 +00:00
|
|
|
);
|
2023-12-18 11:16:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (isWDSEnabled) {
|
|
|
|
|
return (
|
|
|
|
|
<WDSThemeProvider theme={theme}>{renderChildren()}</WDSThemeProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return renderChildren();
|
2019-11-26 10:45:46 +00:00
|
|
|
} catch (error) {
|
2021-07-05 05:49:43 +00:00
|
|
|
log.error("Error rendering DSL", error);
|
|
|
|
|
Sentry.captureException(error);
|
2019-11-26 10:45:46 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2023-02-03 05:47:40 +00:00
|
|
|
};
|
2019-02-10 13:06:05 +00:00
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default Canvas;
|