melonykit 1.14.0 → 1.15.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/dist/browser-A1IeCWNV.js +119 -0
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/browser-BhVmije8.js +0 -93
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { a as e } from "./functions-mQlYMSp2.js";
|
|
2
|
+
import { signal as t } from "@preact/signals";
|
|
3
|
+
import { useEffect as n, useMemo as r } from "preact/hooks";
|
|
4
|
+
// src/browser/_route-to.js
|
|
5
|
+
function i(e, t = !1) {
|
|
6
|
+
t ? history.replaceState(null, "", e) : history.pushState(null, "", e), dispatchEvent(new PopStateEvent("popstate"));
|
|
7
|
+
}
|
|
8
|
+
// src/browser/_use-query.js
|
|
9
|
+
var a = /* @__PURE__ */ new Map(), o = null;
|
|
10
|
+
function s({ endpoint: n, refetchEvent: i } = {}) {
|
|
11
|
+
let a = r(() => {
|
|
12
|
+
let r = t(null), i = t(!1), a = t(null);
|
|
13
|
+
async function o() {
|
|
14
|
+
i.value = !0, a.value = null;
|
|
15
|
+
try {
|
|
16
|
+
let t = await e({
|
|
17
|
+
url: n,
|
|
18
|
+
method: "GET"
|
|
19
|
+
});
|
|
20
|
+
if (!t.success) throw Error("Could not query data.");
|
|
21
|
+
r.value = t.data;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.log(e), a.value = e;
|
|
24
|
+
} finally {
|
|
25
|
+
i.value = !1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
data: r,
|
|
30
|
+
loading: i,
|
|
31
|
+
error: a,
|
|
32
|
+
refetch: o
|
|
33
|
+
};
|
|
34
|
+
}, [n]);
|
|
35
|
+
return l(a, i), a;
|
|
36
|
+
}
|
|
37
|
+
function c({ query: n, variables: i, refetchEvent: a } = {}) {
|
|
38
|
+
let o = JSON.stringify(i ?? null), s = r(() => {
|
|
39
|
+
let r = t(null), i = t(!1), a = t(null);
|
|
40
|
+
async function s() {
|
|
41
|
+
i.value = !0, a.value = null;
|
|
42
|
+
try {
|
|
43
|
+
let t = await e({
|
|
44
|
+
url: "/api/graphql",
|
|
45
|
+
method: "POST",
|
|
46
|
+
body: {
|
|
47
|
+
query: n,
|
|
48
|
+
variables: JSON.parse(o)
|
|
49
|
+
}
|
|
50
|
+
}), i = t.data?.errors?.[0];
|
|
51
|
+
if (!t.success || i) throw Error(i?.message ?? "Could not query data.");
|
|
52
|
+
r.value = t.data?.data ?? null;
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log(e), a.value = e;
|
|
55
|
+
} finally {
|
|
56
|
+
i.value = !1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
data: r,
|
|
61
|
+
loading: i,
|
|
62
|
+
error: a,
|
|
63
|
+
refetch: s
|
|
64
|
+
};
|
|
65
|
+
}, [n, o]);
|
|
66
|
+
return l(s, a), s;
|
|
67
|
+
}
|
|
68
|
+
function l(e, t) {
|
|
69
|
+
n(() => {
|
|
70
|
+
let n = t ? d(t, e.refetch) : () => {};
|
|
71
|
+
return e.refetch(), n;
|
|
72
|
+
}, [e, t]);
|
|
73
|
+
}
|
|
74
|
+
function u() {
|
|
75
|
+
return o ??= new EventSource("/api/client-events"), o;
|
|
76
|
+
}
|
|
77
|
+
function d(e, t) {
|
|
78
|
+
let n = u();
|
|
79
|
+
if (!a.has(e)) {
|
|
80
|
+
let t = /* @__PURE__ */ new Set(), r = (e) => {
|
|
81
|
+
let n = e.data ? JSON.parse(e.data) : null;
|
|
82
|
+
for (let e of t) e(n);
|
|
83
|
+
};
|
|
84
|
+
a.set(e, {
|
|
85
|
+
callbacks: t,
|
|
86
|
+
handler: r
|
|
87
|
+
}), n.addEventListener(e, r);
|
|
88
|
+
}
|
|
89
|
+
let r = a.get(e);
|
|
90
|
+
return r.callbacks.add(t), () => {
|
|
91
|
+
r.callbacks.delete(t), r.callbacks.size > 0 || (n.removeEventListener(e, r.handler), a.delete(e));
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// src/browser/_get-client-setting.js
|
|
95
|
+
function f(e, t = null) {
|
|
96
|
+
if (typeof window > "u" || !e) return t;
|
|
97
|
+
try {
|
|
98
|
+
let n = window.localStorage.getItem(p(e));
|
|
99
|
+
return n === null ? t : JSON.parse(n);
|
|
100
|
+
} catch {
|
|
101
|
+
return t;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function p(e) {
|
|
105
|
+
return `melonykit:${e}`;
|
|
106
|
+
}
|
|
107
|
+
// src/browser/_set-client-setting.js
|
|
108
|
+
function m(e, t) {
|
|
109
|
+
if (typeof window > "u" || !e) return !1;
|
|
110
|
+
try {
|
|
111
|
+
return window.localStorage.setItem(h(e), JSON.stringify(t)), !0;
|
|
112
|
+
} catch {
|
|
113
|
+
return !1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function h(e) {
|
|
117
|
+
return `melonykit:${e}`;
|
|
118
|
+
}
|
|
119
|
+
export { i as a, s as i, f as n, c as r, m as t };
|
package/dist/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as getClientSetting,
|
|
1
|
+
export { n as getClientSetting, a as routeTo, t as setClientSetting, r as useGraphqlQuery, i as useQuery } from "./browser-A1IeCWNV.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as e, d as t, n } from "./functions-mQlYMSp2.js";
|
|
2
|
-
import { n as r, t as i } from "./browser-
|
|
2
|
+
import { n as r, t as i } from "./browser-A1IeCWNV.js";
|
|
3
3
|
import { useSignal as a } from "@preact/signals";
|
|
4
4
|
import { useEffect as o, useId as s, useRef as c } from "preact/hooks";
|
|
5
5
|
import { Fragment as l, jsx as u, jsxs as d } from "preact/jsx-runtime";
|
package/package.json
CHANGED
package/dist/browser-BhVmije8.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { a as e } from "./functions-mQlYMSp2.js";
|
|
2
|
-
import { signal as t } from "@preact/signals";
|
|
3
|
-
import { useEffect as n, useMemo as r } from "preact/hooks";
|
|
4
|
-
// src/browser/_route-to.js
|
|
5
|
-
function i(e, t = !1) {
|
|
6
|
-
t ? history.replaceState(null, "", e) : history.pushState(null, "", e), dispatchEvent(new PopStateEvent("popstate"));
|
|
7
|
-
}
|
|
8
|
-
// src/browser/_use-query.js
|
|
9
|
-
var a = /* @__PURE__ */ new Map(), o = null;
|
|
10
|
-
function s({ endpoint: i, event: a, refreshEvent: o }) {
|
|
11
|
-
let s = r(() => {
|
|
12
|
-
let n = t(null), r = t(!1), a = t(null);
|
|
13
|
-
async function o() {
|
|
14
|
-
r.value = !0, a.value = null;
|
|
15
|
-
try {
|
|
16
|
-
let t = await e({
|
|
17
|
-
url: i,
|
|
18
|
-
method: "GET"
|
|
19
|
-
});
|
|
20
|
-
if (!t.success) throw Error("Could not query data.");
|
|
21
|
-
n.value = t.data;
|
|
22
|
-
} catch (e) {
|
|
23
|
-
console.log(e), a.value = e;
|
|
24
|
-
} finally {
|
|
25
|
-
r.value = !1;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
data: n,
|
|
30
|
-
loading: r,
|
|
31
|
-
error: a,
|
|
32
|
-
refetch: o
|
|
33
|
-
};
|
|
34
|
-
}, [i]);
|
|
35
|
-
return n(() => {
|
|
36
|
-
let e = a ? l(a, (e) => {
|
|
37
|
-
s.data.value = e;
|
|
38
|
-
}) : o ? l(o, () => {
|
|
39
|
-
s.refetch();
|
|
40
|
-
}) : () => {};
|
|
41
|
-
return s.refetch(), e;
|
|
42
|
-
}, [
|
|
43
|
-
s,
|
|
44
|
-
a,
|
|
45
|
-
o
|
|
46
|
-
]), s;
|
|
47
|
-
}
|
|
48
|
-
function c() {
|
|
49
|
-
return o ||= new EventSource("/api/client-events"), o;
|
|
50
|
-
}
|
|
51
|
-
function l(e, t) {
|
|
52
|
-
let n = c();
|
|
53
|
-
if (!a.has(e)) {
|
|
54
|
-
let t = /* @__PURE__ */ new Set(), r = (e) => {
|
|
55
|
-
let n = e.data ? JSON.parse(e.data) : null;
|
|
56
|
-
for (let e of t) e(n);
|
|
57
|
-
};
|
|
58
|
-
a.set(e, {
|
|
59
|
-
callbacks: t,
|
|
60
|
-
handler: r
|
|
61
|
-
}), n.addEventListener(e, r);
|
|
62
|
-
}
|
|
63
|
-
let r = a.get(e);
|
|
64
|
-
return r.callbacks.add(t), () => {
|
|
65
|
-
r.callbacks.delete(t), r.callbacks.size === 0 && (n.removeEventListener(e, r.handler), a.delete(e));
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// src/browser/_get-client-setting.js
|
|
69
|
-
function u(e, t = null) {
|
|
70
|
-
if (typeof window > "u" || !e) return t;
|
|
71
|
-
try {
|
|
72
|
-
let n = window.localStorage.getItem(d(e));
|
|
73
|
-
return n === null ? t : JSON.parse(n);
|
|
74
|
-
} catch {
|
|
75
|
-
return t;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function d(e) {
|
|
79
|
-
return `melonykit:${e}`;
|
|
80
|
-
}
|
|
81
|
-
// src/browser/_set-client-setting.js
|
|
82
|
-
function f(e, t) {
|
|
83
|
-
if (typeof window > "u" || !e) return !1;
|
|
84
|
-
try {
|
|
85
|
-
return window.localStorage.setItem(p(e), JSON.stringify(t)), !0;
|
|
86
|
-
} catch {
|
|
87
|
-
return !1;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function p(e) {
|
|
91
|
-
return `melonykit:${e}`;
|
|
92
|
-
}
|
|
93
|
-
export { i, u as n, s as r, f as t };
|