2020-04-15 12:15:12 +00:00
|
|
|
import React, { lazy, Suspense } from "react";
|
2020-03-20 11:17:30 +00:00
|
|
|
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
|
|
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
|
|
|
|
import { EventType } from "constants/ActionConstants";
|
|
|
|
|
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
|
|
|
|
|
import { VALIDATION_TYPES } from "constants/WidgetValidation";
|
|
|
|
|
import { TriggerPropertiesMap } from "utils/WidgetFactory";
|
2020-04-16 08:32:58 +00:00
|
|
|
import Skeleton from "components/utils/Skeleton";
|
2020-03-20 11:17:30 +00:00
|
|
|
|
2020-04-15 12:15:12 +00:00
|
|
|
const RichtextEditorComponent = lazy(() =>
|
2020-04-17 04:59:43 +00:00
|
|
|
import(
|
|
|
|
|
/* webpackChunkName: "rte",webpackPrefetch: 2 */ "components/designSystems/appsmith/RichTextEditorComponent"
|
|
|
|
|
),
|
2020-04-15 12:15:12 +00:00
|
|
|
);
|
|
|
|
|
|
2020-03-20 11:17:30 +00:00
|
|
|
class RichTextEditorWidget extends BaseWidget<
|
|
|
|
|
RichTextEditorWidgetProps,
|
|
|
|
|
WidgetState
|
|
|
|
|
> {
|
|
|
|
|
static getPropertyValidationMap(): WidgetPropertyValidationType {
|
|
|
|
|
return {
|
|
|
|
|
placeholder: VALIDATION_TYPES.TEXT,
|
|
|
|
|
defaultValue: VALIDATION_TYPES.TEXT,
|
|
|
|
|
isDisabled: VALIDATION_TYPES.BOOLEAN,
|
|
|
|
|
isVisible: VALIDATION_TYPES.BOOLEAN,
|
2020-03-31 10:40:52 +00:00
|
|
|
onTextChange: VALIDATION_TYPES.ACTION_SELECTOR,
|
2020-03-20 11:17:30 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
|
|
|
|
return {
|
|
|
|
|
onTextChange: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
super.componentDidMount();
|
2020-04-15 11:42:11 +00:00
|
|
|
if (this.props.defaultText) {
|
|
|
|
|
this.updateWidgetMetaProperty("text", this.props.defaultText);
|
2020-03-20 11:17:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: RichTextEditorWidgetProps) {
|
|
|
|
|
super.componentDidUpdate(prevProps);
|
2020-04-15 11:42:11 +00:00
|
|
|
if (this.props.defaultText) {
|
|
|
|
|
if (this.props.defaultText !== prevProps.defaultText) {
|
|
|
|
|
this.updateWidgetMetaProperty("text", this.props.defaultText);
|
2020-03-20 11:17:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 11:42:11 +00:00
|
|
|
onValueChange = (text: string) => {
|
|
|
|
|
this.updateWidgetMetaProperty("text", text);
|
2020-03-20 11:17:30 +00:00
|
|
|
if (this.props.onTextChange) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
dynamicString: this.props.onTextChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_TEXT_CHANGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
|
|
|
|
return (
|
2020-04-16 08:32:58 +00:00
|
|
|
<Suspense fallback={<Skeleton />}>
|
2020-04-15 12:15:12 +00:00
|
|
|
<RichtextEditorComponent
|
|
|
|
|
onValueChange={this.onValueChange}
|
|
|
|
|
defaultValue={this.props.text}
|
|
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
placeholder={this.props.placeholder}
|
|
|
|
|
key={this.props.widgetId}
|
|
|
|
|
isDisabled={this.props.isDisabled}
|
|
|
|
|
isVisible={this.props.isVisible}
|
|
|
|
|
/>
|
|
|
|
|
</Suspense>
|
2020-03-20 11:17:30 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWidgetType(): WidgetType {
|
|
|
|
|
return "RICH_TEXT_EDITOR_WIDGET";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputValidator {
|
|
|
|
|
validationRegex: string;
|
|
|
|
|
errorMessage: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RichTextEditorWidgetProps extends WidgetProps {
|
2020-04-15 11:42:11 +00:00
|
|
|
defaultText?: string;
|
2020-03-20 11:17:30 +00:00
|
|
|
text?: string;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
onTextChange?: string;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
isVisible?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default RichTextEditorWidget;
|