-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): create the utis functions
- Loading branch information
1 parent
7fa7836
commit 653cdab
Showing
9 changed files
with
81 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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,20 @@ | ||
export class EventPostMessage { | ||
constructor( | ||
private action: Window, | ||
private origin: '*', | ||
) {} | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
send(type?: string, data?: any, origin?: string) { | ||
this.action.postMessage({ type, data }, origin ?? this.origin) | ||
} | ||
} | ||
|
||
export class EventListener { | ||
constructor(private action: Window | HTMLElement) {} | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
get(type: string, eventHandler: (event: any) => void) { | ||
this.action.addEventListener(type, eventHandler) | ||
} | ||
} |
This file contains 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 @@ | ||
export * from './events' |
This file contains 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,11 @@ | ||
export function create(type: string) { | ||
const iframe = document.createElement('iframe') | ||
|
||
iframe.setAttribute('name', type) | ||
iframe.setAttribute('src', 'https://develop.d3krxmg1839vaa.amplifyapp.com/') | ||
iframe.setAttribute('width', '100%') | ||
iframe.setAttribute('height', '100%') | ||
iframe.setAttribute('frameborder', '0') | ||
|
||
return iframe | ||
} |
This file contains 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,3 @@ | ||
export * from './create' | ||
export * from './loaded' | ||
export * from './parsedString' |
This file contains 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,21 @@ | ||
import { EventPostMessage } from '../form-events' | ||
import { create } from './create' | ||
import { camelToKebabCase } from './parsedString' | ||
|
||
export function loaded(configFields: any) { | ||
const fields = Object.keys(configFields) | ||
|
||
for (const field of fields) { | ||
const iframe = create(field) | ||
const iframeName = camelToKebabCase(field) | ||
if (!iframe || !iframe.contentWindow) return | ||
|
||
const iframePostmessage = new EventPostMessage(iframe.contentWindow, '*') | ||
|
||
iframe.onload = () => { | ||
iframePostmessage.send('setTypeField', { | ||
fieldType: iframeName, | ||
}) | ||
} | ||
} | ||
} |
This file contains 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,3 @@ | ||
export function camelToKebabCase(camelCaseString: string) { | ||
return camelCaseString.replace(/([A-Z])/g, '-$1').toLowerCase() | ||
} |
This file contains 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './form-elements' | ||
export * from './form-values' | ||
export * from './form-iframes' | ||
export * from './form-events' |
This file contains 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