melonykit 0.7.1 → 0.7.3

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,64 @@
1
+ import { r as e } from "./functions-C8th2V6m.js";
2
+ import { signal as t } from "@preact/signals";
3
+ import { useEffect as n, useMemo as r } from "preact/hooks";
4
+ //#region 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
+ //#endregion
9
+ //#region src/browser/_use-api-query.js
10
+ var a = /* @__PURE__ */ new Map(), o = null;
11
+ function s({ endpoint: i, event: a }) {
12
+ let o = r(() => {
13
+ let n = t(null), r = t(!1), a = t(null);
14
+ async function o() {
15
+ r.value = !0, a.value = null;
16
+ try {
17
+ let t = await e({
18
+ url: `/api/${i}`,
19
+ method: "GET"
20
+ });
21
+ if (!t.success) throw Error("Could not query data.");
22
+ n.value = t.data;
23
+ } catch (e) {
24
+ console.log(e), a.value = e;
25
+ } finally {
26
+ r.value = !1;
27
+ }
28
+ }
29
+ return {
30
+ data: n,
31
+ loading: r,
32
+ error: a,
33
+ refetch: o
34
+ };
35
+ }, [i]);
36
+ return n(() => {
37
+ let e = l(a, (e) => {
38
+ o.data.value = e;
39
+ });
40
+ return o.refetch(), e;
41
+ }, [o, a]), o;
42
+ }
43
+ function c() {
44
+ return o ||= new EventSource("/api/events"), o;
45
+ }
46
+ function l(e, t) {
47
+ let n = c();
48
+ if (!a.has(e)) {
49
+ let t = /* @__PURE__ */ new Set(), r = (e) => {
50
+ let n = e.data ? JSON.parse(e.data) : null;
51
+ for (let e of t) e(n);
52
+ };
53
+ a.set(e, {
54
+ callbacks: t,
55
+ handler: r
56
+ }), n.addEventListener(e, r);
57
+ }
58
+ let r = a.get(e);
59
+ return r.callbacks.add(t), () => {
60
+ r.callbacks.delete(t), r.callbacks.size === 0 && (n.removeEventListener(e, r.handler), a.delete(e));
61
+ };
62
+ }
63
+ //#endregion
64
+ export { i as routeTo, s as useApiQuery };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i as e, o as t } from "./functions-C8th2V6m.js";
2
- import { Fragment as n, jsx as r, jsxs as i } from "preact/jsx-runtime";
3
- import { useSignal as a } from "@preact/signals";
4
- import { useEffect as o, useId as s } from "preact/hooks";
2
+ import { useSignal as n } from "@preact/signals";
3
+ import { useEffect as r, useId as i } from "preact/hooks";
4
+ import { Fragment as a, jsx as o, jsxs as s } from "preact/jsx-runtime";
5
5
  //#region node_modules/@emotion/sheet/dist/emotion-sheet.esm.js
6
6
  function c(e) {
7
7
  if (e.sheet) return e.sheet;
@@ -861,9 +861,9 @@ var Qe = "<svg xmlns=\"http://www.w3.org/2000/svg\" style=\"position:absolute;wi
861
861
  //#endregion
862
862
  //#region src/components/_app-wrapper.jsx
863
863
  function tt({ maxWidth: e = "67.5rem", children: t }) {
864
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
864
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
865
865
  className: nt.base,
866
- children: /* @__PURE__ */ r("div", {
866
+ children: /* @__PURE__ */ o("div", {
867
867
  className: nt.inner,
868
868
  style: { maxWidth: e },
869
869
  children: t
@@ -889,12 +889,12 @@ var nt = {
889
889
  padding: 8rem 0;
890
890
  margin: 0 auto;
891
891
  `
892
- }, rt = ({ type: e = "normal", width: t = "100%", value: i = 0 }) => /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
892
+ }, rt = ({ type: e = "normal", width: t = "100%", value: n = 0 }) => /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
893
893
  className: X.base,
894
894
  style: { width: t },
895
- children: /* @__PURE__ */ r("div", {
895
+ children: /* @__PURE__ */ o("div", {
896
896
  className: q(X.value, X[e] ?? X.normal),
897
- style: { width: `${i}%` }
897
+ style: { width: `${n}%` }
898
898
  })
899
899
  }) }), X = {
900
900
  base: J`
@@ -924,14 +924,14 @@ var nt = {
924
924
  };
925
925
  //#endregion
926
926
  //#region src/components/_box.jsx
927
- function it({ className: e, width: t, height: i, children: a }) {
928
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
927
+ function it({ className: e, width: t, height: n, children: r }) {
928
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
929
929
  className: q(at.base, e),
930
930
  style: {
931
931
  width: t,
932
- height: i
932
+ height: n
933
933
  },
934
- children: a
934
+ children: r
935
935
  }) });
936
936
  }
937
937
  var at = { base: J`
@@ -944,17 +944,17 @@ var at = { base: J`
944
944
  ` };
945
945
  //#endregion
946
946
  //#region src/components/_icon.jsx
947
- function Z({ className: e, size: t = "1.25rem", color: i = Y.colors.fore.primary, iconName: a, isSpinning: o }) {
948
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("svg", {
947
+ function Z({ className: e, size: t = "1.25rem", color: n = Y.colors.fore.primary, iconName: r, isSpinning: i }) {
948
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("svg", {
949
949
  className: q(ot.base, e),
950
950
  style: {
951
- color: i,
951
+ color: n,
952
952
  width: t,
953
953
  height: t
954
954
  },
955
955
  "aria-hidden": "true",
956
- "is-spinning": o || void 0,
957
- children: /* @__PURE__ */ r("use", { href: `#icon-${a}` })
956
+ "is-spinning": i || void 0,
957
+ children: /* @__PURE__ */ o("use", { href: `#icon-${r}` })
958
958
  }) });
959
959
  }
960
960
  var ot = { base: J`
@@ -983,10 +983,10 @@ var ot = { base: J`
983
983
  ` };
984
984
  //#endregion
985
985
  //#region src/components/_button.jsx
986
- function st({ type: e = "primary", label: t, iconName: o, isDisabled: s = !1, isLoading: c = !1, onClick: l }) {
987
- let u = o || c, d = a(null);
986
+ function st({ type: e = "primary", label: t, iconName: r, isDisabled: i = !1, isLoading: c = !1, onClick: l }) {
987
+ let u = r || c, d = n(null);
988
988
  function f(e) {
989
- if (s || c) return;
989
+ if (i || c) return;
990
990
  e.stopPropagation(), e.preventDefault();
991
991
  let t = e.currentTarget.getBoundingClientRect();
992
992
  d.value = {
@@ -995,29 +995,29 @@ function st({ type: e = "primary", label: t, iconName: o, isDisabled: s = !1, is
995
995
  size: Math.max(t.width, t.height) * 2
996
996
  }, l?.(e);
997
997
  }
998
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("button", {
998
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("button", {
999
999
  type: "button",
1000
1000
  className: q(Q.base, Q[e] ?? Q.normal),
1001
1001
  "has-icon": u,
1002
- "is-disabled": s || void 0,
1002
+ "is-disabled": i || void 0,
1003
1003
  "is-loading": c || void 0,
1004
1004
  "is-clickable": !!l || void 0,
1005
- disabled: s || c,
1005
+ disabled: i || c,
1006
1006
  onClick: f,
1007
1007
  children: [
1008
- u && /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
1008
+ u && /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
1009
1009
  className: J`
1010
1010
  ${Y.extends.verticalCenter}
1011
1011
 
1012
1012
  left: .5rem;
1013
1013
  `,
1014
- children: c ? /* @__PURE__ */ r(Z, {
1014
+ children: c ? /* @__PURE__ */ o(Z, {
1015
1015
  name: "loader",
1016
1016
  isSpinning: !0
1017
- }) : /* @__PURE__ */ r(Z, { name: o })
1017
+ }) : /* @__PURE__ */ o(Z, { name: r })
1018
1018
  }) }),
1019
1019
  t,
1020
- d.value && /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("span", {
1020
+ d.value && /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("span", {
1021
1021
  className: Q.ripple,
1022
1022
  style: {
1023
1023
  left: d.value.x,
@@ -1083,14 +1083,14 @@ var ct = Ze`
1083
1083
  };
1084
1084
  //#endregion
1085
1085
  //#region src/components/_layout.jsx
1086
- function lt({ className: e, height: t, direction: i = "row", justify: a, align: o, gap: s, children: c }) {
1087
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
1086
+ function lt({ className: e, height: t, direction: n = "row", justify: r, align: i, gap: s, children: c }) {
1087
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
1088
1088
  className: q(ut.base, e),
1089
1089
  style: {
1090
1090
  height: t,
1091
- flexDirection: i,
1092
- justifyContent: a,
1093
- alignItems: o,
1091
+ flexDirection: n,
1092
+ justifyContent: r,
1093
+ alignItems: i,
1094
1094
  gap: s == null ? void 0 : `${s / 2}rem`
1095
1095
  },
1096
1096
  children: c
@@ -1101,11 +1101,11 @@ var ut = { base: J`
1101
1101
  ` };
1102
1102
  //#endregion
1103
1103
  //#region src/components/_text.jsx
1104
- function dt({ as: e = "span", className: t, size: i = "normal", color: a = Y.colors.fore.primary, children: o }) {
1105
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r(e, {
1106
- className: q(ft.base, ft[i] ?? ft.normal, t),
1107
- style: { color: a },
1108
- children: o
1104
+ function dt({ as: e = "span", className: t, size: n = "normal", color: r = Y.colors.fore.primary, children: i }) {
1105
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(e, {
1106
+ className: q(ft.base, ft[n] ?? ft.normal, t),
1107
+ style: { color: r },
1108
+ children: i
1109
1109
  }) });
1110
1110
  }
1111
1111
  var ft = {
@@ -1128,11 +1128,11 @@ var ft = {
1128
1128
  };
1129
1129
  //#endregion
1130
1130
  //#region src/components/_headline.jsx
1131
- function pt({ as: e = "h2", className: t, size: i = "normal", color: a = Y.colors.fore.primary, children: o }) {
1132
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r(e, {
1133
- className: q(mt.base, mt[i] ?? mt.normal, t),
1134
- style: { color: a },
1135
- children: o
1131
+ function pt({ as: e = "h2", className: t, size: n = "normal", color: r = Y.colors.fore.primary, children: i }) {
1132
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(e, {
1133
+ className: q(mt.base, mt[n] ?? mt.normal, t),
1134
+ style: { color: r },
1135
+ children: i
1136
1136
  }) });
1137
1137
  }
1138
1138
  var mt = {
@@ -1158,7 +1158,7 @@ var mt = {
1158
1158
  //#endregion
1159
1159
  //#region src/components/_space.jsx
1160
1160
  function ht({ size: e = 1 }) {
1161
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
1161
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
1162
1162
  "aria-hidden": "true",
1163
1163
  style: {
1164
1164
  height: e > 0 ? `${e}rem` : 0,
@@ -1168,20 +1168,20 @@ function ht({ size: e = 1 }) {
1168
1168
  }
1169
1169
  //#endregion
1170
1170
  //#region src/components/_text-field.jsx
1171
- function gt({ placeholder: e, value: t, width: o, isDisabled: c, onChange: l }) {
1172
- let u = s(), d = a(t);
1171
+ function gt({ placeholder: e, value: t, width: r, isDisabled: c, onChange: l }) {
1172
+ let u = i(), d = n(t);
1173
1173
  function f({ target: e }) {
1174
1174
  d.value = e.value, l?.(d.value);
1175
1175
  }
1176
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("div", {
1176
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("div", {
1177
1177
  className: _t.base,
1178
- style: { width: o },
1178
+ style: { width: r },
1179
1179
  "is-disabled": c,
1180
- children: [!d.value && e && /* @__PURE__ */ r("label", {
1180
+ children: [!d.value && e && /* @__PURE__ */ o("label", {
1181
1181
  className: _t.label,
1182
1182
  htmlFor: u,
1183
1183
  children: e
1184
- }), /* @__PURE__ */ r("input", {
1184
+ }), /* @__PURE__ */ o("input", {
1185
1185
  id: u,
1186
1186
  name: u,
1187
1187
  className: _t.input,
@@ -1225,22 +1225,22 @@ var _t = {
1225
1225
  `
1226
1226
  }, vt = 28, yt = 3, bt = 11;
1227
1227
  function xt({ label: e, isChecked: t, isDisabled: c, onChange: l }) {
1228
- let u = s(), d = a(t);
1229
- o(() => d.value = t, [t]);
1228
+ let u = i(), d = n(t);
1229
+ r(() => d.value = t, [t]);
1230
1230
  function f() {
1231
1231
  let e = !d.value;
1232
1232
  d.value = e, l?.(e);
1233
1233
  }
1234
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("div", {
1234
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("div", {
1235
1235
  className: St.base,
1236
1236
  children: [
1237
- /* @__PURE__ */ r("label", {
1237
+ /* @__PURE__ */ o("label", {
1238
1238
  className: St.label,
1239
1239
  htmlFor: u,
1240
1240
  "is-disabled": c,
1241
1241
  children: e
1242
1242
  }),
1243
- /* @__PURE__ */ r("input", {
1243
+ /* @__PURE__ */ o("input", {
1244
1244
  id: u,
1245
1245
  type: "checkbox",
1246
1246
  className: St.checkbox,
@@ -1248,7 +1248,7 @@ function xt({ label: e, isChecked: t, isDisabled: c, onChange: l }) {
1248
1248
  disabled: c,
1249
1249
  onChange: f
1250
1250
  }),
1251
- /* @__PURE__ */ r("label", {
1251
+ /* @__PURE__ */ o("label", {
1252
1252
  className: St.value,
1253
1253
  htmlFor: u,
1254
1254
  "is-disabled": c
@@ -1312,18 +1312,18 @@ var St = {
1312
1312
  };
1313
1313
  //#endregion
1314
1314
  //#region src/components/_tag.jsx
1315
- function Ct({ className: t, variant: a = "normal", iconName: o, label: s }) {
1316
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("div", {
1317
- className: q(wt.base, wt[a] ?? wt.normal, t),
1318
- "has-icon": !e(o),
1319
- children: [o && /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r(Z, {
1315
+ function Ct({ className: t, variant: n = "normal", iconName: r, label: i }) {
1316
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("div", {
1317
+ className: q(wt.base, wt[n] ?? wt.normal, t),
1318
+ "has-icon": !e(r),
1319
+ children: [r && /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(Z, {
1320
1320
  className: J`
1321
1321
  ${Y.extends.verticalCenter}
1322
1322
  left: .3rem;
1323
1323
  `,
1324
- name: o,
1324
+ name: r,
1325
1325
  size: ".9rem"
1326
- }) }), s]
1326
+ }) }), i]
1327
1327
  }) });
1328
1328
  }
1329
1329
  var wt = { base: J`
@@ -1342,21 +1342,21 @@ var wt = { base: J`
1342
1342
  ` };
1343
1343
  //#endregion
1344
1344
  //#region src/components/_icon-button.jsx
1345
- function Tt({ iconName: e, color: t, isDisabled: i, onClick: a }) {
1346
- function o(e) {
1347
- i || (e.stopPropagation(), e.preventDefault(), a?.(e));
1345
+ function Tt({ iconName: e, color: t, isDisabled: n, onClick: r }) {
1346
+ function i(e) {
1347
+ n || (e.stopPropagation(), e.preventDefault(), r?.(e));
1348
1348
  }
1349
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("button", {
1349
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("button", {
1350
1350
  className: Et.base,
1351
- "is-disabled": i || void 0,
1352
- "is-clickable": !!a || void 0,
1353
- disabled: i,
1354
- onClick: o,
1355
- children: /* @__PURE__ */ r(Z, {
1351
+ "is-disabled": n || void 0,
1352
+ "is-clickable": !!r || void 0,
1353
+ disabled: n,
1354
+ onClick: i,
1355
+ children: /* @__PURE__ */ o(Z, {
1356
1356
  color: t,
1357
1357
  className: J`${Y.extends.centrate}`,
1358
1358
  iconName: e,
1359
- isDisabled: i
1359
+ isDisabled: n
1360
1360
  })
1361
1361
  }) });
1362
1362
  }
@@ -1377,21 +1377,21 @@ var Et = { base: J`
1377
1377
  ` };
1378
1378
  //#endregion
1379
1379
  //#region src/components/_tab-box.jsx
1380
- function Dt({ className: e, width: t, height: o, initialIndex: c = 0, items: l = [], onChange: u }) {
1381
- let d = s(), f = Math.max(l.length - 1, 0), p = a(Math.min(Math.max(c, 0), f)), m = Math.min(p.value, f);
1380
+ function Dt({ className: e, width: t, height: r, initialIndex: c = 0, items: l = [], onChange: u }) {
1381
+ let d = i(), f = Math.max(l.length - 1, 0), p = n(Math.min(Math.max(c, 0), f)), m = Math.min(p.value, f);
1382
1382
  function h(e) {
1383
1383
  e !== m && (p.value = e, u?.(e, l[e]));
1384
1384
  }
1385
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("div", {
1385
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("div", {
1386
1386
  className: q($.base, e),
1387
1387
  style: { width: t },
1388
- children: [/* @__PURE__ */ r(it, {
1388
+ children: [/* @__PURE__ */ o(it, {
1389
1389
  className: $.box,
1390
- height: o,
1391
- children: /* @__PURE__ */ r("div", {
1390
+ height: r,
1391
+ children: /* @__PURE__ */ o("div", {
1392
1392
  className: $.track,
1393
1393
  style: { transform: `translateX(-${m * 100}%)` },
1394
- children: l.map((e, t) => /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
1394
+ children: l.map((e, t) => /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
1395
1395
  id: `${d}-panel-${t}`,
1396
1396
  className: $.panel,
1397
1397
  role: "tabpanel",
@@ -1401,29 +1401,29 @@ function Dt({ className: e, width: t, height: o, initialIndex: c = 0, items: l =
1401
1401
  children: e.content
1402
1402
  }, e.id ?? t) }))
1403
1403
  })
1404
- }), l.length > 0 && /* @__PURE__ */ r(n, { children: /* @__PURE__ */ r("div", {
1404
+ }), l.length > 0 && /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o("div", {
1405
1405
  className: $.tabs,
1406
1406
  role: "tablist",
1407
1407
  children: l.map((e, t) => {
1408
- let a = t === m, o = e.notification != null;
1409
- return /* @__PURE__ */ r(n, { children: /* @__PURE__ */ i("button", {
1408
+ let n = t === m, r = e.notification != null;
1409
+ return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ s("button", {
1410
1410
  id: `${d}-tab-${t}`,
1411
1411
  className: $.tab,
1412
1412
  type: "button",
1413
1413
  role: "tab",
1414
1414
  "aria-controls": `${d}-panel-${t}`,
1415
1415
  "aria-label": e.label ?? `Tab ${t + 1}`,
1416
- "aria-selected": a,
1417
- tabIndex: a ? 0 : -1,
1418
- "is-active": a || void 0,
1416
+ "aria-selected": n,
1417
+ tabIndex: n ? 0 : -1,
1418
+ "is-active": n || void 0,
1419
1419
  onClick: () => h(t),
1420
1420
  children: [
1421
- e.iconName && /* @__PURE__ */ r(Z, {
1421
+ e.iconName && /* @__PURE__ */ o(Z, {
1422
1422
  iconName: e.iconName,
1423
1423
  size: "1rem"
1424
1424
  }),
1425
- e.label && /* @__PURE__ */ r("span", { children: e.label }),
1426
- o && /* @__PURE__ */ r("span", {
1425
+ e.label && /* @__PURE__ */ o("span", { children: e.label }),
1426
+ r && /* @__PURE__ */ o("span", {
1427
1427
  className: $.notification,
1428
1428
  "aria-label": `${e.notification} notifications`,
1429
1429
  children: e.notification
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Vadim Hermann",
3
3
  "name": "melonykit",
4
- "version": "0.7.1",
4
+ "version": "0.7.3",
5
5
  "type": "module",
6
6
  "description": "Preact based ui and utility functions toolkit",
7
7
  "main": "./dist/index.js",