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 WidgetFactory from "WidgetProvider/factory";
|
|
|
|
|
import type { CanvasWidgetStructure } from "WidgetProvider/constants";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
|
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
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";
|
|
|
|
|
import { previewModeSelector } from "selectors/editorSelectors";
|
|
|
|
|
import { getSelectedAppTheme } from "selectors/appThemingSelectors";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { getViewportClassName } from "layoutSystems/autolayout/utils/AutoLayoutUtils";
|
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";
|
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;
|
2022-05-04 09:45:57 +00:00
|
|
|
const isPreviewMode = useSelector(previewModeSelector);
|
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-07-26 12:40:44 +00:00
|
|
|
const isWDSV2Enabled = useFeatureFlag("ab_wds_enabled");
|
|
|
|
|
const { theme } = useTheme({
|
|
|
|
|
borderRadius: selectedTheme.properties.borderRadius.appBorderRadius,
|
|
|
|
|
seedColor: selectedTheme.properties.colors.primaryColor,
|
|
|
|
|
});
|
2022-05-04 09:45:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* background for canvas
|
|
|
|
|
*/
|
|
|
|
|
let backgroundForCanvas;
|
|
|
|
|
|
2023-03-23 11:41:58 +00:00
|
|
|
if (isPreviewMode || isAppSettingsPaneWithNavigationTabOpen) {
|
2023-07-26 12:40:44 +00:00
|
|
|
if (isWDSV2Enabled) {
|
|
|
|
|
backgroundForCanvas = "var(--color-bg)";
|
|
|
|
|
} else {
|
|
|
|
|
backgroundForCanvas = "initial";
|
|
|
|
|
}
|
2022-05-04 09:45:57 +00:00
|
|
|
} else {
|
2023-07-26 12:40:44 +00:00
|
|
|
if (isWDSV2Enabled) {
|
|
|
|
|
backgroundForCanvas = "var(--color-bg)";
|
|
|
|
|
} else {
|
|
|
|
|
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";
|
2019-11-26 10:45:46 +00:00
|
|
|
try {
|
|
|
|
|
return (
|
2023-07-26 12:40:44 +00:00
|
|
|
<WDSThemeProvider theme={theme}>
|
2023-09-12 14:14:02 +00:00
|
|
|
<Wrapper
|
|
|
|
|
$enableMainCanvasResizer={!!props.enableMainCanvasResizer}
|
2023-07-26 12:40:44 +00:00
|
|
|
background={backgroundForCanvas}
|
2023-08-11 12:16:11 +00:00
|
|
|
className={`relative t--canvas-artboard ${paddingBottomClass} transition-all duration-400 ${marginHorizontalClass} ${getViewportClassName(
|
2023-07-26 12:40:44 +00:00
|
|
|
canvasWidth,
|
|
|
|
|
)}`}
|
|
|
|
|
data-testid="t--canvas-artboard"
|
|
|
|
|
id="art-board"
|
|
|
|
|
ref={focusRef}
|
|
|
|
|
width={canvasWidth}
|
|
|
|
|
>
|
|
|
|
|
{props.widgetsStructure.widgetId &&
|
|
|
|
|
WidgetFactory.createWidget(
|
|
|
|
|
props.widgetsStructure,
|
|
|
|
|
RenderModes.CANVAS,
|
|
|
|
|
)}
|
2023-09-12 14:14:02 +00:00
|
|
|
</Wrapper>
|
2023-07-26 12:40:44 +00:00
|
|
|
</WDSThemeProvider>
|
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;
|