-
Notifications
You must be signed in to change notification settings - Fork 6
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
FIO-9201: Fix DataTable in quick inline embed issues #177
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Formio } from "sdk"; | ||
|
||
export type ResourceToDomOptions = { | ||
name: string, | ||
src: string | Array<string>, | ||
formio: typeof Formio, | ||
onload?: (ready: Promise<any>) => void, | ||
rootElement?: HTMLElement | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { isBoolean, isString } from 'lodash'; | ||
import { BaseComponent, Component } from 'types'; | ||
import { BaseComponent, Component, ResourceToDomOptions } from 'types'; | ||
|
||
/** | ||
* Escapes RegEx characters in provided String value. | ||
|
@@ -64,6 +64,63 @@ export function registerEphemeralState( | |
}); | ||
} | ||
|
||
export function attachResourceToDom(options: ResourceToDomOptions) { | ||
const { name, formio, onload, rootElement } = options; | ||
let { src } = options; | ||
src = Array.isArray(src) ? src : [src]; | ||
src.forEach((lib: any) => { | ||
let attrs: any = {}; | ||
let elementType = ''; | ||
if (typeof lib === 'string') { | ||
lib = { | ||
type: 'script', | ||
src: lib, | ||
}; | ||
} | ||
switch (lib.type) { | ||
case 'script': | ||
elementType = 'script'; | ||
attrs = { | ||
src: lib.src, | ||
type: 'text/javascript', | ||
defer: true, | ||
async: true, | ||
referrerpolicy: 'origin', | ||
}; | ||
break; | ||
case 'styles': | ||
elementType = 'link'; | ||
attrs = { | ||
href: lib.src, | ||
rel: 'stylesheet', | ||
}; | ||
break; | ||
} | ||
|
||
// Add the script to the top of the page. | ||
const element = document.createElement(elementType); | ||
if (element.setAttribute) { | ||
for (const attr in attrs) { | ||
element.setAttribute(attr, attrs[attr]); | ||
} | ||
} | ||
if (onload) { | ||
element.addEventListener('load', () => { | ||
formio.libraries[name].loaded = true; | ||
onload(formio.libraries[name].ready); | ||
}); | ||
} | ||
if (rootElement) { | ||
rootElement.insertAdjacentElement('afterend', element); | ||
return; | ||
} | ||
const { head } = document; | ||
if (head) { | ||
head.appendChild(element); | ||
} | ||
}); | ||
Comment on lines
+113
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this attach the element twice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, since there's a flag in |
||
} | ||
|
||
export function resetEphemeralState(component: Component) { | ||
if (component.ephemeralState) { | ||
delete component.ephemeralState; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update jsdocs with new parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added