melonykit 1.20.0 → 1.21.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.
@@ -0,0 +1,115 @@
1
+ import { a as e, o as t } from "./functions-Komj9AN0.js";
2
+ import { signal as n } from "@preact/signals";
3
+ import { useEffect as r, useMemo as i } from "preact/hooks";
4
+ // src/browser/_route-to.js
5
+ function a(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 o = /* @__PURE__ */ new Map(), s = null;
10
+ function c({ endpoint: e, refetchEvent: r } = {}) {
11
+ let a = i(() => {
12
+ let r = n(null), i = n(!1), a = n(null);
13
+ async function o() {
14
+ i.value = !0, a.value = null;
15
+ try {
16
+ let n = await t({
17
+ url: e,
18
+ method: "GET"
19
+ });
20
+ if (!n.success) throw Error("Could not query data.");
21
+ r.value = n.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
+ }, [e]);
35
+ return u(a, r), a;
36
+ }
37
+ function l({ query: t, variables: r, refetchEvent: a } = {}) {
38
+ let o = JSON.stringify(r ?? null), s = i(() => {
39
+ let r = n(null), i = n(!1), a = n(null);
40
+ async function s() {
41
+ i.value = !0, a.value = null;
42
+ try {
43
+ let n = await e({
44
+ query: t,
45
+ variables: JSON.parse(o)
46
+ });
47
+ if (!n.success) throw Error(n.errors?.[0]?.message ?? "Could not query data.");
48
+ r.value = n.data ?? null;
49
+ } catch (e) {
50
+ console.log(e), a.value = e;
51
+ } finally {
52
+ i.value = !1;
53
+ }
54
+ }
55
+ return {
56
+ data: r,
57
+ loading: i,
58
+ error: a,
59
+ refetch: s
60
+ };
61
+ }, [t, o]);
62
+ return u(s, a), s;
63
+ }
64
+ function u(e, t) {
65
+ r(() => {
66
+ let n = t ? f(t, e.refetch) : () => {};
67
+ return e.refetch(), n;
68
+ }, [e, t]);
69
+ }
70
+ function d() {
71
+ return s ??= new EventSource("/api/client-events"), s;
72
+ }
73
+ function f(e, t) {
74
+ let n = d();
75
+ if (!o.has(e)) {
76
+ let t = /* @__PURE__ */ new Set(), r = (e) => {
77
+ let n = e.data ? JSON.parse(e.data) : null;
78
+ for (let e of t) e(n);
79
+ };
80
+ o.set(e, {
81
+ callbacks: t,
82
+ handler: r
83
+ }), n.addEventListener(e, r);
84
+ }
85
+ let r = o.get(e);
86
+ return r.callbacks.add(t), () => {
87
+ r.callbacks.delete(t), r.callbacks.size > 0 || (n.removeEventListener(e, r.handler), o.delete(e));
88
+ };
89
+ }
90
+ // src/browser/_get-client-setting.js
91
+ function p(e, t = null) {
92
+ if (typeof window > "u" || !e) return t;
93
+ try {
94
+ let n = window.localStorage.getItem(m(e));
95
+ return n === null ? t : JSON.parse(n);
96
+ } catch {
97
+ return t;
98
+ }
99
+ }
100
+ function m(e) {
101
+ return `melonykit:${e}`;
102
+ }
103
+ // src/browser/_set-client-setting.js
104
+ function h(e, t) {
105
+ if (typeof window > "u" || !e) return !1;
106
+ try {
107
+ return window.localStorage.setItem(g(e), JSON.stringify(t)), !0;
108
+ } catch {
109
+ return !1;
110
+ }
111
+ }
112
+ function g(e) {
113
+ return `melonykit:${e}`;
114
+ }
115
+ export { a, c as i, p as n, l as r, h as t };
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- export { n as getClientSetting, a as routeTo, t as setClientSetting, r as useGraphqlQuery, i as useQuery } from "./browser-A1IeCWNV.js";
1
+ export { n as getClientSetting, a as routeTo, t as setClientSetting, r as useGraphqlQuery, i as useQuery } from "./browser-CtfJzdHf.js";
@@ -304,27 +304,44 @@ async function M({ url: e, body: t, method: n = "POST", headers: r = {} } = {})
304
304
  }
305
305
  return a.ok || (s.error = s.data ?? /* @__PURE__ */ Error(`Request failed with status ${a.status}.`)), s;
306
306
  }
307
+ // src/functions/_request-graphql.js
308
+ async function N({ query: e, variables: t } = {}) {
309
+ let n = await M({
310
+ url: "/api/graphql",
311
+ method: "POST",
312
+ body: {
313
+ query: e,
314
+ variables: t
315
+ }
316
+ }), { data: r, errors: i } = n.data ?? {};
317
+ return {
318
+ ...n,
319
+ success: n.success && !i?.length,
320
+ data: r,
321
+ errors: i
322
+ };
323
+ }
307
324
  // src/functions/_risk-reward.js
308
- function N(e = {}) {
325
+ function P(e = {}) {
309
326
  let { entry: t, exit: n, riskRatio: r = 20 } = e ?? {};
310
327
  if (!c(t) || t <= 0 || !c(n) || n <= 0 || !c(r) || r <= 0) return null;
311
328
  let i = (n - t) / t / (r / 100);
312
329
  return Math.round(i * 10) / 10;
313
330
  }
314
331
  // src/functions/_size.js
315
- function P(e) {
332
+ function F(e) {
316
333
  return e == null ? 0 : Array.isArray(e) || typeof e == "string" ? e.length : typeof e == "object" || typeof e == "function" ? Object.keys(e).length : 0;
317
334
  }
318
335
  // src/functions/_slugify.js
319
- function F(e) {
336
+ function I(e) {
320
337
  return typeof e == "string" ? e.trim().toLowerCase().replace(/ä/g, "ae").replace(/ö/g, "oe").replace(/ü/g, "ue").replace(/ß/g, "ss").replace(/æ/g, "ae").replace(/œ/g, "oe").replace(/ø/g, "o").normalize("NFD").replace(/\p{Diacritic}/gu, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "";
321
338
  }
322
339
  // src/functions/_to-number.js
323
- function I(e, t = null) {
340
+ function L(e, t = null) {
324
341
  let n = typeof e == "number" ? e : typeof e == "string" && e.trim() !== "" ? Number(e) : NaN;
325
342
  if (!Number.isFinite(n)) return null;
326
343
  if (t == null) return n;
327
344
  let r = 10 ** t;
328
345
  return Math.round(n * r) / r;
329
346
  }
330
- export { i as C, e as E, a as S, t as T, u as _, M as a, s as b, k as c, E as d, T as f, _ as g, S as h, N as i, O as l, C as m, F as n, j as o, w as p, P as r, A as s, I as t, D as u, l as v, n as w, o as x, c as y };
347
+ export { a as C, e as D, t as E, o as S, n as T, _, N as a, c as b, A as c, D as d, E as f, S as g, C as h, P as i, k as l, w as m, I as n, M as o, T as p, F as r, j as s, L as t, O as u, u as v, i as w, s as x, l as y };
package/dist/functions.js CHANGED
@@ -1 +1 @@
1
- export { E as average, w as camelCaseToTitleCase, C as convertHexToRgba, v as createCache, _ as darkenHexColor, g as formatDate, S as isArray, h as isBoolean, x as isEmptyArray, f as isEmptyObject, d as isEmptyString, u as isFloat, b as isFunction, l as isInteger, m as isNil, y as isNumber, p as isObject, T as isString, c as kebabCaseToCamelCase, s as kebabCaseToTitleCase, o as median, a as request, i as riskReward, r as size, n as slugify, t as toNumber } from "./functions-mQlYMSp2.js";
1
+ export { D as average, T as camelCaseToTitleCase, w as convertHexToRgba, y as createCache, v as darkenHexColor, _ as formatDate, C as isArray, g as isBoolean, S as isEmptyArray, p as isEmptyObject, f as isEmptyString, d as isFloat, x as isFunction, u as isInteger, h as isNil, b as isNumber, m as isObject, E as isString, l as kebabCaseToCamelCase, c as kebabCaseToTitleCase, s as median, o as request, a as requestGraphql, i as riskReward, r as size, n as slugify, t as toNumber } from "./functions-Komj9AN0.js";
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { useSignal as e } from "@preact/signals";
2
2
  import { Fragment as t, jsx as n, jsxs as r } from "preact/jsx-runtime";
3
- import { T as i, _ as a, d as o, n as s } from "./functions-mQlYMSp2.js";
3
+ import { E as i, f as a, n as o, v as s } from "./functions-Komj9AN0.js";
4
4
  import { useEffect as c, useId as l, useRef as u } from "preact/hooks";
5
- import { n as d, t as f } from "./browser-A1IeCWNV.js";
5
+ import { n as d, t as f } from "./browser-CtfJzdHf.js";
6
6
  // node_modules/@emotion/sheet/dist/emotion-sheet.esm.js
7
7
  function p(e) {
8
8
  if (e.sheet) return e.sheet;
@@ -2053,7 +2053,7 @@ var Tr = xt`
2053
2053
  `,
2054
2054
  secondary: k`
2055
2055
  color: ${A.colors.deepOcean};
2056
- border-color: ${a(A.colors.tangerineSnack, .2)};
2056
+ border-color: ${s(A.colors.tangerineSnack, .2)};
2057
2057
  background-color: ${A.colors.tangerineSnack};
2058
2058
  `,
2059
2059
  neutral: k`
@@ -2321,7 +2321,7 @@ function Fr(e, t) {
2321
2321
  return d(Ir(e), t);
2322
2322
  }
2323
2323
  function Ir(e) {
2324
- let t = s(e);
2324
+ let t = o(e);
2325
2325
  return t ? `accordions:${t}:is-open` : "";
2326
2326
  }
2327
2327
  var Lr = {
@@ -2553,15 +2553,15 @@ var Hr = {
2553
2553
  transition: width .3s ease;
2554
2554
  `,
2555
2555
  normal: k`
2556
- border: solid 1px ${a(A.colors.lightBreeze, .3)};
2556
+ border: solid 1px ${s(A.colors.lightBreeze, .3)};
2557
2557
  background-color: ${A.colors.lightBreeze};
2558
2558
  `,
2559
2559
  warn: k`
2560
- border: solid 1px ${a(A.colors.tangerineSnack, .2)};
2560
+ border: solid 1px ${s(A.colors.tangerineSnack, .2)};
2561
2561
  background-color: ${A.colors.tangerineSnack};
2562
2562
  `,
2563
2563
  danger: k`
2564
- border: solid 1px ${a(A.colors.coralBlush, .3)};
2564
+ border: solid 1px ${s(A.colors.coralBlush, .3)};
2565
2565
  background-color: ${A.colors.coralBlush};
2566
2566
  `
2567
2567
  };
@@ -2947,7 +2947,7 @@ var ri = {
2947
2947
  height: 1rem;
2948
2948
  margin-top: -.375rem;
2949
2949
  border-radius: 50%;
2950
- border: solid 1px ${a(A.colors.lightBreeze, .3)};
2950
+ border: solid 1px ${s(A.colors.lightBreeze, .3)};
2951
2951
  background-color: ${A.colors.lightBreeze};
2952
2952
  transition: transform .15s ease;
2953
2953
  }
@@ -3157,7 +3157,7 @@ var si = xt`
3157
3157
  --checked-background-color: ${A.colors.lightBreeze};
3158
3158
  `,
3159
3159
  secondary: k`
3160
- --checked-border-color: ${a(A.colors.tangerineSnack, .2)};
3160
+ --checked-border-color: ${s(A.colors.tangerineSnack, .2)};
3161
3161
  --checked-background-color: ${A.colors.tangerineSnack};
3162
3162
  `,
3163
3163
  input: k`
@@ -3265,7 +3265,7 @@ var mi = {
3265
3265
  background-color: ${A.colors.softPottery};
3266
3266
 
3267
3267
  &:before {
3268
- border-color: ${a(A.colors.lightBreeze, .3)};
3268
+ border-color: ${s(A.colors.lightBreeze, .3)};
3269
3269
  background-color: ${A.colors.lightBreeze};
3270
3270
  transform: translate(${fi}px, -50%);
3271
3271
  }
@@ -3303,10 +3303,10 @@ var mi = {
3303
3303
  `
3304
3304
  };
3305
3305
  // src/components/_tag.jsx
3306
- function hi({ as: e = "div", className: i, variant: a = "normal", iconName: s = "", label: c }) {
3306
+ function hi({ as: e = "div", className: i, variant: o = "normal", iconName: s = "", label: c }) {
3307
3307
  return /* @__PURE__ */ n(t, { children: /* @__PURE__ */ r(e, {
3308
- className: yt(gi.base, gi[a] ?? gi.normal, i),
3309
- "has-icon": !o(s),
3308
+ className: yt(gi.base, gi[o] ?? gi.normal, i),
3309
+ "has-icon": !a(s),
3310
3310
  children: [s && /* @__PURE__ */ n(t, { children: /* @__PURE__ */ n(Tt, {
3311
3311
  className: k`
3312
3312
  ${A.extends.verticalCenter}
@@ -3363,7 +3363,7 @@ function _i({ title: i, actionBar: a, initialOpen: o = !0, children: s }) {
3363
3363
  }) });
3364
3364
  }
3365
3365
  function vi(e) {
3366
- let t = s(e);
3366
+ let t = o(e);
3367
3367
  return t ? `tag-boxes:${t}:is-open` : "";
3368
3368
  }
3369
3369
  var yi = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Vadim Hermann",
3
3
  "name": "melonykit",
4
- "version": "1.20.0",
4
+ "version": "1.21.0",
5
5
  "type": "module",
6
6
  "description": "Preact based ui and utility functions toolkit",
7
7
  "main": "./dist/index.js",
@@ -1,119 +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: 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 };