dry-ux 1.40.0 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,8 +7,9 @@ export declare const preventDefault: (handler?: (event: any) => void) => (event:
|
|
|
7
7
|
* Imports a script and returns a promise that resolves when the script is loaded.
|
|
8
8
|
* @param resourceUrl The url of the script to load.
|
|
9
9
|
* @param singleton If true, the script will only be loaded once.
|
|
10
|
+
* @param placement "body" or "head" to specify where the script should be placed.
|
|
10
11
|
*/
|
|
11
|
-
export declare const importScript: (resourceUrl: string, singleton?: boolean) => Promise<void>;
|
|
12
|
+
export declare const importScript: (resourceUrl: string, singleton?: boolean, placement?: "body" | "head") => Promise<void>;
|
|
12
13
|
/**
|
|
13
14
|
* Imports a stylesheet and adds it to the head.
|
|
14
15
|
* @param resourceUrl The url of the stylesheet to load.
|
|
@@ -15,15 +15,21 @@ exports.preventDefault = preventDefault;
|
|
|
15
15
|
* Imports a script and returns a promise that resolves when the script is loaded.
|
|
16
16
|
* @param resourceUrl The url of the script to load.
|
|
17
17
|
* @param singleton If true, the script will only be loaded once.
|
|
18
|
+
* @param placement "body" or "head" to specify where the script should be placed.
|
|
18
19
|
*/
|
|
19
|
-
const importScript = (resourceUrl, singleton = true) => new Promise(resolve => {
|
|
20
|
+
const importScript = (resourceUrl, singleton = true, placement = "body") => new Promise(resolve => {
|
|
20
21
|
React.useEffect(() => {
|
|
21
22
|
const script = document.createElement("script");
|
|
22
23
|
if (!$(`script[src='${resourceUrl}']`).length) {
|
|
23
24
|
script.src = resourceUrl;
|
|
24
25
|
script.async = true;
|
|
25
26
|
script.onload = () => resolve();
|
|
26
|
-
|
|
27
|
+
if (placement === "head") {
|
|
28
|
+
document.head.appendChild(script);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
document.body.appendChild(script);
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
34
|
else {
|
|
29
35
|
resolve();
|