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-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-12-01 12:39:21 +00:00
|
|
|
import { getAppThemeSettings } from "@appsmith/selectors/applicationSelectors";
|
2024-03-13 06:23:49 +00:00
|
|
|
import CodeModeTooltip from "pages/Editor/WidgetsEditor/CodeModeTooltip";
|
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;
|
|
|
|
|
canvasWidth: number;
|
2023-09-12 14:14:02 +00:00
|
|
|
enableMainCanvasResizer?: boolean;
|
2019-08-29 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-06 07:26:47 +00:00
|
|
|
const StyledWDSThemeProvider = styled(WDSThemeProvider)`
|
|
|
|
|
min-height: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
`;
|
|
|
|
|
|
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
|
|
|
}>`
|
2024-02-06 07:26:47 +00:00
|
|
|
flex: 1;
|
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-09-15 17:00:10 +00:00
|
|
|
|
2023-12-01 12:39:21 +00:00
|
|
|
const themeSetting = useSelector(getAppThemeSettings);
|
|
|
|
|
const wdsThemeProps = {
|
|
|
|
|
borderRadius: themeSetting.borderRadius,
|
|
|
|
|
seedColor: themeSetting.accentColor,
|
2023-12-28 08:28:33 +00:00
|
|
|
colorMode: themeSetting.colorMode.toLowerCase(),
|
2024-03-05 11:53:18 +00:00
|
|
|
fontFamily: themeSetting.fontFamily,
|
2023-12-01 12:39:21 +00:00
|
|
|
userSizing: themeSetting.sizing,
|
|
|
|
|
userDensity: themeSetting.density,
|
feat: Tabler Icons (#30248)
Fixes #28443
Fixes #27866
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced `IconSelectControlV2` for enhanced icon selection with
keyboard navigation and state updates.
- Added new `iconStyle` theme property for users to define icon styles
globally.
- Implemented dynamic icon loading with fallback options, improving icon
management.
- **Enhancements**
- Simplified icon usage across various components like `Button`,
`IconButton`, `Menu`, `ModalHeader`, `TextInput`, and more by directly
using icon names.
- Enhanced `Tag` component to use a generic `Icon` component for the
remove action.
- **Style Updates**
- Added CSS classes for resizing, boundary display, and pointer event
handling.
- Updated icon size definitions using CSS custom properties.
- **Bug Fixes**
- Fixed icon-related issues in `Button`, `ActionGroup`, `Menu`, and
`TextInput` components to ensure proper icon display.
- **Documentation**
- Updated storybook and test cases to reflect new icon selection and
usage.
- **Refactor**
- Refactored theme and token management to include `iconStyle` for
consistent icon theming.
- Refined the `ButtonGroupWidget` and `MenuButtonWidget` to use the new
icon selection mechanism.
- **Chores**
- Cleaned up unused icon imports and components across the codebase to
streamline the icon system.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-01-19 08:54:44 +00:00
|
|
|
iconStyle: themeSetting.iconStyle.toLowerCase(),
|
2024-03-05 11:53:18 +00:00
|
|
|
} as Parameters<typeof useTheme>[0];
|
|
|
|
|
// in case of non-WDS theme, we will pass an empty object to useTheme hook
|
|
|
|
|
// so that fixedLayout theme does not break because of calculations done in useTheme
|
|
|
|
|
const { theme } = useTheme(isWDSEnabled ? wdsThemeProps : {});
|
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
|
|
|
|
|
|
|
|
const renderChildren = () => {
|
2019-11-26 10:45:46 +00:00
|
|
|
return (
|
2024-03-13 06:23:49 +00:00
|
|
|
<CodeModeTooltip>
|
|
|
|
|
<Wrapper
|
|
|
|
|
$enableMainCanvasResizer={!!props.enableMainCanvasResizer}
|
|
|
|
|
background={isWDSEnabled ? "" : backgroundForCanvas}
|
|
|
|
|
className={`relative t--canvas-artboard ${paddingBottomClass} transition-all duration-400 ${marginHorizontalClass} ${getViewportClassName(
|
|
|
|
|
canvasWidth,
|
|
|
|
|
)}`}
|
|
|
|
|
data-testid={"t--canvas-artboard"}
|
|
|
|
|
id={CANVAS_ART_BOARD}
|
|
|
|
|
ref={isWDSEnabled ? undefined : focusRef}
|
|
|
|
|
width={canvasWidth}
|
|
|
|
|
>
|
|
|
|
|
{props.widgetsStructure.widgetId &&
|
|
|
|
|
renderAppsmithCanvas(props.widgetsStructure as WidgetProps)}
|
|
|
|
|
</Wrapper>
|
|
|
|
|
</CodeModeTooltip>
|
2019-11-26 10:45:46 +00:00
|
|
|
);
|
2023-12-18 11:16:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (isWDSEnabled) {
|
|
|
|
|
return (
|
2024-02-06 07:26:47 +00:00
|
|
|
<StyledWDSThemeProvider theme={theme}>
|
|
|
|
|
{renderChildren()}
|
|
|
|
|
</StyledWDSThemeProvider>
|
2023-12-18 11:16:00 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|