@solid-primitives/script-loader
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -28,2 +28,2 @@ import { ComponentProps, Accessor } from 'solid-js'; | ||
export { ScriptProps, createScriptLoader }; | ||
export { type ScriptProps, createScriptLoader }; |
@@ -11,5 +11,22 @@ import { splitProps, createRenderEffect, onCleanup } from 'solid-js'; | ||
const script = document.createElement("script"); | ||
const [local, scriptProps] = splitProps(props, OMITTED_PROPS); | ||
const eventKeys = Object.keys(props).filter((p) => p.startsWith("on")); | ||
const [local, events, scriptProps] = splitProps( | ||
props, | ||
OMITTED_PROPS, | ||
eventKeys | ||
); | ||
setTimeout(() => spread(script, scriptProps, false, true)); | ||
createRenderEffect(() => { | ||
Object.entries(events).forEach( | ||
([name, handler]) => script.addEventListener( | ||
/^on:?(.*)/.test(name) ? name.startsWith("on:") ? RegExp.$1 : RegExp.$1.toLowerCase() : name, | ||
(ev) => { | ||
Object.defineProperties(ev, { | ||
target: { value: script, enumerable: true }, | ||
currentTarget: { value: script, enumerable: true } | ||
}); | ||
Array.isArray(handler) ? handler[0](handler[1], ev) : typeof handler === "function" && handler?.call(null, Object.assign(ev)); | ||
} | ||
) | ||
); | ||
const src = typeof local.src === "string" ? local.src : local.src(); | ||
@@ -16,0 +33,0 @@ const prop = /^(https?:|\w[\.\w-_%]+|)\//.test(src) ? "src" : "textContent"; |
{ | ||
"name": "@solid-primitives/script-loader", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Primitive to load scripts dynamically", | ||
@@ -5,0 +5,0 @@ "author": "Alex Lohr <alex.lohr@logmein.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10056
107
7