-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Refactor WDS custom widget #38038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5f8901
refactor custom widget
jsartisan 1aca8e5
refactor custom widget
jsartisan f1f4a97
fix comments
jsartisan a95d9e6
move some files
jsartisan 5013696
update templates
jsartisan e0a0eaf
update border in react app
jsartisan eb55fbd
fix typo in comments
jsartisan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/IframeMessenger.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { IframeMessage } from "../types"; | ||
| import { EVENTS } from "./customWidgetscript"; | ||
|
|
||
| export class IframeMessenger { | ||
| private iframe: HTMLIFrameElement; | ||
|
|
||
| constructor(iframe: HTMLIFrameElement) { | ||
| this.iframe = iframe; | ||
| } | ||
|
|
||
| handleMessage = ( | ||
| event: MessageEvent, | ||
| handlers: Record<string, (data: Record<string, unknown>) => void>, | ||
| ) => { | ||
| const iframeWindow = | ||
| this.iframe.contentWindow || this.iframe.contentDocument?.defaultView; | ||
|
|
||
| // Without this check, malicious scripts from other windows could inject | ||
| // unauthorized messages into our application, potentially leading to data | ||
| // breaches or unauthorized state modifications | ||
| if (event.source !== iframeWindow) return; | ||
|
|
||
| // We send an acknowledgement message for every event to ensure reliable communication | ||
| // between the parent window and iframe. This helps in maintaining message ordering | ||
| // and preventing race conditions. | ||
| this.acknowledgeMessage(event.data); | ||
|
|
||
| const handler = handlers[event.data.type]; | ||
|
|
||
| if (handler) { | ||
| handler(event.data.data); | ||
| } | ||
| }; | ||
|
|
||
| private acknowledgeMessage(message: IframeMessage) { | ||
| this.postMessage({ | ||
| type: EVENTS.CUSTOM_WIDGET_MESSAGE_RECEIVED_ACK, | ||
| key: message.key, | ||
| success: true, | ||
| }); | ||
| } | ||
|
|
||
| postMessage(message: IframeMessage) { | ||
| this.iframe.contentWindow?.postMessage(message, "*"); | ||
| } | ||
| } | ||
18 changes: 0 additions & 18 deletions
18
app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/constants.ts
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/createHtmlTemplate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // @ts-expect-error - Type error due to raw loader | ||
| import css from "!!raw-loader!./reset.css"; | ||
|
|
||
| // @ts-expect-error - Type error due to raw loader | ||
| import script from "!!raw-loader!./customWidgetscript.js"; | ||
|
|
||
| // @ts-expect-error - Type error due to raw loader | ||
| import appsmithConsole from "!!raw-loader!./appsmithConsole.js"; | ||
|
|
||
| interface CreateHtmlTemplateProps { | ||
| cssTokens: string; | ||
| onConsole: boolean; | ||
| srcDoc: { html: string; js: string; css: string }; | ||
| } | ||
|
|
||
| export const createHtmlTemplate = (props: CreateHtmlTemplateProps) => { | ||
| const { cssTokens, onConsole, srcDoc } = props; | ||
|
|
||
| return `<html> | ||
| <head> | ||
| <style>${css}</style> | ||
| <style data-appsmith-theme>${cssTokens}</style> | ||
| </head> | ||
| <body> | ||
| ${onConsole ? `<script type="text/javascript">${appsmithConsole}</script>` : ""} | ||
| <script type="module"> | ||
| ${script} | ||
| main(); | ||
| </script> | ||
| ${srcDoc.html} | ||
| <script type="module">${srcDoc.js}</script> | ||
| <style>${srcDoc.css}</style> | ||
| </body> | ||
| </html>`; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.