2021-06-09 09:39:17 +00:00
|
|
|
import React from "react";
|
2021-09-09 15:10:22 +00:00
|
|
|
import BaseWidget, { WidgetState } from "widgets/BaseWidget";
|
2021-07-26 05:50:46 +00:00
|
|
|
import { ValidationTypes } from "constants/WidgetValidation";
|
2021-06-10 05:29:52 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
import IframeComponent from "../component";
|
|
|
|
|
import { IframeWidgetProps } from "../constants";
|
2021-06-09 09:39:17 +00:00
|
|
|
class IframeWidget extends BaseWidget<IframeWidgetProps, WidgetState> {
|
|
|
|
|
static getPropertyPaneConfig() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
sectionName: "General",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "source",
|
|
|
|
|
helpText: "The URL of the page to embed",
|
2021-09-20 10:43:44 +00:00
|
|
|
label: "URL",
|
2021-06-09 09:39:17 +00:00
|
|
|
controlType: "INPUT_TEXT",
|
2021-09-20 10:43:44 +00:00
|
|
|
placeholderText: "https://docs.appsmith.com",
|
2021-06-09 09:39:17 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: {
|
2021-07-28 06:01:09 +00:00
|
|
|
type: ValidationTypes.SAFE_URL,
|
2021-07-26 05:50:46 +00:00
|
|
|
params: {
|
2021-11-02 04:17:49 +00:00
|
|
|
default: "https://www.example.com",
|
2021-07-26 05:50:46 +00:00
|
|
|
},
|
|
|
|
|
},
|
2021-06-09 09:39:17 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "title",
|
|
|
|
|
helpText: "Label the content of the page to embed",
|
|
|
|
|
label: "Title",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
2021-09-20 10:43:44 +00:00
|
|
|
placeholderText: "Documentation",
|
2021-06-09 09:39:17 +00:00
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: { type: ValidationTypes.TEXT },
|
2021-06-09 09:39:17 +00:00
|
|
|
},
|
2021-12-14 07:55:58 +00:00
|
|
|
{
|
|
|
|
|
propertyName: "animateLoading",
|
|
|
|
|
label: "Animate Loading",
|
|
|
|
|
controlType: "SWITCH",
|
|
|
|
|
helpText: "Controls the loading of the widget",
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
validation: { type: ValidationTypes.BOOLEAN },
|
|
|
|
|
},
|
2021-06-09 09:39:17 +00:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-11-26 09:32:04 +00:00
|
|
|
sectionName: "Events",
|
2021-06-09 09:39:17 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
2021-06-21 10:48:00 +00:00
|
|
|
helpText: "Triggers an action when the source URL is changed",
|
2021-06-09 09:39:17 +00:00
|
|
|
propertyName: "onURLChanged",
|
|
|
|
|
label: "onURLChanged",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
helpText: "Triggers an action when a message event is received",
|
|
|
|
|
propertyName: "onMessageReceived",
|
|
|
|
|
label: "onMessageReceived",
|
|
|
|
|
controlType: "ACTION_SELECTOR",
|
|
|
|
|
isJSConvertible: true,
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sectionName: "Styles",
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderColor",
|
|
|
|
|
label: "Border Color",
|
|
|
|
|
controlType: "COLOR_PICKER",
|
|
|
|
|
isBindProperty: false,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderOpacity",
|
|
|
|
|
label: "Border Opacity (%)",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
inputType: "NUMBER",
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.NUMBER,
|
|
|
|
|
params: { min: 0, max: 100, default: 100 },
|
|
|
|
|
},
|
2021-06-09 09:39:17 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
propertyName: "borderWidth",
|
|
|
|
|
label: "Border Width (px)",
|
|
|
|
|
controlType: "INPUT_TEXT",
|
|
|
|
|
isBindProperty: true,
|
|
|
|
|
isTriggerProperty: false,
|
|
|
|
|
inputType: "NUMBER",
|
2021-07-26 05:50:46 +00:00
|
|
|
validation: {
|
|
|
|
|
type: ValidationTypes.NUMBER,
|
|
|
|
|
params: { min: 0, default: 1 },
|
|
|
|
|
},
|
2021-06-09 09:39:17 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-30 06:36:00 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
|
|
|
|
message: undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 09:39:17 +00:00
|
|
|
urlChangedHandler = (url: string) => {
|
2021-06-10 05:29:52 +00:00
|
|
|
if (url && this.props.onURLChanged) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
triggerPropertyName: "onURLChanged",
|
|
|
|
|
dynamicString: this.props.onURLChanged,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_IFRAME_URL_CHANGED,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-06-09 09:39:17 +00:00
|
|
|
};
|
|
|
|
|
|
2021-06-10 08:17:33 +00:00
|
|
|
messageReceivedHandler = (event: MessageEvent) => {
|
|
|
|
|
// Accept messages only from the current iframe
|
2021-06-11 13:16:29 +00:00
|
|
|
if (!this.props.source?.includes(event.origin)) {
|
2021-06-10 08:17:33 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2021-07-30 06:36:00 +00:00
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("message", event.data, {
|
|
|
|
|
triggerPropertyName: "onMessageReceived",
|
|
|
|
|
dynamicString: this.props.onMessageReceived,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_IFRAME_MESSAGE_RECEIVED,
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-06-09 09:39:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getPageView() {
|
2021-06-12 16:08:10 +00:00
|
|
|
const {
|
|
|
|
|
borderColor,
|
|
|
|
|
borderOpacity,
|
|
|
|
|
borderWidth,
|
2021-08-09 09:51:33 +00:00
|
|
|
renderMode,
|
2021-06-12 16:08:10 +00:00
|
|
|
source,
|
|
|
|
|
title,
|
|
|
|
|
widgetId,
|
|
|
|
|
} = this.props;
|
2021-07-28 06:01:09 +00:00
|
|
|
|
2021-06-09 09:39:17 +00:00
|
|
|
return (
|
|
|
|
|
<IframeComponent
|
2021-06-12 16:08:10 +00:00
|
|
|
borderColor={borderColor}
|
|
|
|
|
borderOpacity={borderOpacity}
|
|
|
|
|
borderWidth={borderWidth}
|
2021-06-09 09:39:17 +00:00
|
|
|
onMessageReceived={this.messageReceivedHandler}
|
|
|
|
|
onURLChanged={this.urlChangedHandler}
|
2021-08-09 09:51:33 +00:00
|
|
|
renderMode={renderMode}
|
2021-06-12 16:08:10 +00:00
|
|
|
source={source}
|
|
|
|
|
title={title}
|
|
|
|
|
widgetId={widgetId}
|
2021-06-09 09:39:17 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
static getWidgetType(): string {
|
|
|
|
|
return "IFRAME_WIDGET";
|
2021-06-09 09:39:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default IframeWidget;
|