- Adds Web workers and does evaluations in off the main thread - Removes any need to store functions in the data tree and only keeps them around while evaluating - Maintains a stored data tree in the redux state - Evaluates based on editor events instead of state changes
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import * as React from "react";
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
|
import { WidgetType, RenderModes } from "constants/WidgetConstants";
|
|
import ImageComponent from "components/designSystems/appsmith/ImageComponent";
|
|
import {
|
|
WidgetPropertyValidationType,
|
|
BASE_WIDGET_VALIDATION,
|
|
} from "utils/WidgetValidation";
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
|
import * as Sentry from "@sentry/react";
|
|
import { EventType } from "constants/ActionConstants";
|
|
import { TriggerPropertiesMap } from "utils/WidgetFactory";
|
|
|
|
class ImageWidget extends BaseWidget<ImageWidgetProps, WidgetState> {
|
|
constructor(props: ImageWidgetProps) {
|
|
super(props);
|
|
this.onImageClick = this.onImageClick.bind(this);
|
|
}
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
return {
|
|
...BASE_WIDGET_VALIDATION,
|
|
image: VALIDATION_TYPES.TEXT,
|
|
imageShape: VALIDATION_TYPES.TEXT,
|
|
defaultImage: VALIDATION_TYPES.TEXT,
|
|
};
|
|
}
|
|
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
|
return {
|
|
onClick: true,
|
|
};
|
|
}
|
|
getPageView() {
|
|
return (
|
|
<ImageComponent
|
|
widgetId={this.props.widgetId}
|
|
imageUrl={this.props.image || ""}
|
|
onClick={this.props.onClick ? this.onImageClick : undefined}
|
|
showHoverPointer={this.props.renderMode === RenderModes.PAGE}
|
|
defaultImageUrl={this.props.defaultImage}
|
|
isLoading={this.props.isLoading}
|
|
/>
|
|
);
|
|
}
|
|
|
|
onImageClick() {
|
|
if (this.props.onClick) {
|
|
super.executeAction({
|
|
dynamicString: this.props.onClick,
|
|
event: {
|
|
type: EventType.ON_CLICK,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
getWidgetType(): WidgetType {
|
|
return "IMAGE_WIDGET";
|
|
}
|
|
}
|
|
|
|
export type ImageShape = "RECTANGLE" | "CIRCLE" | "ROUNDED";
|
|
|
|
export interface ImageWidgetProps extends WidgetProps {
|
|
image: string;
|
|
imageShape: ImageShape;
|
|
defaultImage: string;
|
|
onClick?: string;
|
|
}
|
|
|
|
export default ImageWidget;
|
|
export const ProfiledImageWidget = Sentry.withProfiler(ImageWidget);
|