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";
|
2020-06-09 12:04:38 +00:00
|
|
|
import {
|
|
|
|
|
TriggerPropertiesMap,
|
|
|
|
|
DerivedPropertiesMap,
|
|
|
|
|
} from "utils/WidgetFactory";
|
2020-04-16 08:32:58 +00:00
|
|
|
import Skeleton from "components/utils/Skeleton";
|
2020-08-28 17:23:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2020-09-15 06:59:58 +00:00
|
|
|
import { retryPromise } from "utils/AppsmithUtils";
|
2020-10-06 09:01:51 +00:00
|
|
|
import withMeta, { WithMeta } from "./MetaHOC";
|
2020-03-20 11:17:30 +00:00
|
|
|
|
2020-09-15 06:59:58 +00:00
|
|
|
const RichTextEditorComponent = lazy(() =>
|
|
|
|
|
retryPromise(() =>
|
|
|
|
|
import(
|
|
|
|
|
/* webpackChunkName: "rte",webpackPrefetch: 2 */ "components/designSystems/appsmith/RichTextEditorComponent"
|
|
|
|
|
),
|
2020-04-17 04:59:43 +00:00
|
|
|
),
|
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 {
|
2020-08-07 18:09:54 +00:00
|
|
|
text: VALIDATION_TYPES.TEXT,
|
2020-03-20 11:17:30 +00:00
|
|
|
placeholder: VALIDATION_TYPES.TEXT,
|
|
|
|
|
defaultValue: VALIDATION_TYPES.TEXT,
|
|
|
|
|
isDisabled: VALIDATION_TYPES.BOOLEAN,
|
|
|
|
|
isVisible: VALIDATION_TYPES.BOOLEAN,
|
2020-07-06 08:16:42 +00:00
|
|
|
// onTextChange: VALIDATION_TYPES.ACTION_SELECTOR,
|
2020-03-20 11:17:30 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
|
|
|
|
return {
|
|
|
|
|
onTextChange: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 16:15:09 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
|
|
|
|
text: undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
|
|
|
return {
|
|
|
|
|
text: "defaultText",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 12:04:38 +00:00
|
|
|
static getDerivedPropertiesMap(): DerivedPropertiesMap {
|
|
|
|
|
return {
|
2020-06-09 13:10:42 +00:00
|
|
|
value: `{{this.text}}`,
|
2020-06-09 12:04:38 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-15 11:42:11 +00:00
|
|
|
onValueChange = (text: string) => {
|
2020-10-06 09:01:51 +00:00
|
|
|
this.props.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-09-15 06:59:58 +00:00
|
|
|
<RichTextEditorComponent
|
2020-04-15 12:15:12 +00:00
|
|
|
onValueChange={this.onValueChange}
|
2020-08-07 18:09:54 +00:00
|
|
|
defaultValue={this.props.text || ""}
|
2020-04-15 12:15:12 +00:00
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 09:01:51 +00:00
|
|
|
export interface RichTextEditorWidgetProps extends WidgetProps, WithMeta {
|
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;
|
2020-08-28 17:23:07 +00:00
|
|
|
export const ProfiledRichTextEditorWidget = Sentry.withProfiler(
|
2020-10-06 09:01:51 +00:00
|
|
|
withMeta(RichTextEditorWidget),
|
2020-08-28 17:23:07 +00:00
|
|
|
);
|