@daz4126/helium 0.15.0 → 0.16.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.
- package/helium.js +12 -5
- package/package.json +1 -1
package/helium.js
CHANGED
|
@@ -22,11 +22,18 @@ export default function helium(data = {}) {
|
|
|
22
22
|
const ajax = (u,m,o={},p={}) => {
|
|
23
23
|
if(o.loading) o.target = update(o.loading,o.target,o.action) || o.target;
|
|
24
24
|
const fd = p instanceof FormData, t = document.querySelector('meta[name="csrf-token"]')?.content;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const url = new URL(u, window.location.href);
|
|
26
|
+
const sameOrigin = url.origin === window.location.origin;
|
|
27
|
+
fetch(u, {
|
|
28
|
+
method: m,
|
|
29
|
+
headers: {
|
|
30
|
+
Accept:"text/vnd.turbo-stream.html,application/json,text/html",
|
|
31
|
+
...(!fd && m !== "GET" && {"Content-Type":"application/json"}),
|
|
32
|
+
...(sameOrigin && t ? {"X-CSRF-Token": t} : {})
|
|
33
|
+
},
|
|
34
|
+
body: m === "GET" ? null : (fd ? p : JSON.stringify(p)),
|
|
35
|
+
credentials: sameOrigin ? "same-origin" : "omit"
|
|
36
|
+
})
|
|
30
37
|
.then(r => {
|
|
31
38
|
const type = r.headers.get("content-type") || "";
|
|
32
39
|
return (type.includes("turbo-stream") ? r.text().then(d => ({ t: true, d })) :
|