@mauroandre/velojs 0.0.15 → 0.0.16

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.
@@ -1,48 +1,56 @@
1
- import { jsx as o, jsxs as p, Fragment as L } from "preact/jsx-runtime";
2
- import { Link as v } from "wouter-preact";
3
- import { __veloUpdatePending as E } from "./hooks.js";
4
- function k({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
1
+ import { jsx as o, jsxs as p, Fragment as $ } from "preact/jsx-runtime";
2
+ import { useRouter as v, Link as E } from "wouter-preact";
3
+ import { __veloUpdatePending as y } from "./hooks.js";
4
+ function O({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
5
5
  const n = process.env.NODE_ENV !== "production";
6
6
  e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
7
7
  const i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: "image/x-icon" });
8
8
  if (n)
9
- return /* @__PURE__ */ p(L, { children: [
9
+ return /* @__PURE__ */ p($, { children: [
10
10
  i,
11
11
  /* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
12
12
  /* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
13
13
  ] });
14
14
  const r = typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js";
15
- return /* @__PURE__ */ p(L, { children: [
15
+ return /* @__PURE__ */ p($, { children: [
16
16
  i,
17
17
  /* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css"}` }),
18
18
  /* @__PURE__ */ o("script", { type: "module", src: `${e}/${r}` })
19
19
  ] });
20
20
  }
21
- function $(e, t) {
21
+ function h(e, t) {
22
22
  let n = e;
23
23
  for (const [i, r] of Object.entries(t))
24
24
  n = n.replace(`:${i}`, r);
25
25
  return n;
26
26
  }
27
- function g({ to: e, params: t, search: n, absolute: i, ...r }) {
28
- const c = typeof e != "string", s = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, f = t ? $(s, t) : s, m = c && i ? `~${f}` : f, _ = n ? `?${new URLSearchParams(n).toString()}` : "", S = `${m}${_}`;
29
- if (typeof window < "u" && E.value) {
30
- const u = c ? e.metadata?.fullPath ?? s : s, a = `${t ? $(u, t) : u}${_}`, { onClick: d, ...h } = r;
27
+ function j({ to: e, params: t, search: n, absolute: i, ...r }) {
28
+ const c = typeof e != "string", u = v(), _ = c ? (i ? e.metadata?.fullPath : e.metadata?.path) ?? "/" : e, l = t ? h(_, t) : _, L = c && i ? `~${l}` : l, a = n ? `?${new URLSearchParams(n).toString()}` : "", m = `${L}${a}`;
29
+ if (typeof window < "u" && y.value) {
30
+ let f;
31
+ if (c) {
32
+ const s = e.metadata?.fullPath ?? _;
33
+ f = `${t ? h(s, t) : s}${a}`;
34
+ } else {
35
+ const s = l.replace(/^~/, "");
36
+ f = `${!l.startsWith("~") && u.base ? u.base : ""}${s}${a}`;
37
+ }
38
+ const { onClick: d, ...S } = r;
31
39
  return /* @__PURE__ */ o(
32
40
  "a",
33
41
  {
34
- href: a,
35
- onClick: (l) => {
36
- d && d(l), l.defaultPrevented || (l.preventDefault(), window.location.href = a);
42
+ href: f,
43
+ onClick: (s) => {
44
+ d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = f);
37
45
  },
38
- ...h
46
+ ...S
39
47
  }
40
48
  );
41
49
  }
42
- return /* @__PURE__ */ o(v, { to: S, ...r });
50
+ return /* @__PURE__ */ o(E, { to: m, ...r });
43
51
  }
44
52
  export {
45
- g as Link,
46
- k as Scripts,
47
- $ as substituteParams
53
+ j as Link,
54
+ O as Scripts,
55
+ h as substituteParams
48
56
  };
package/dist/hooks.js CHANGED
@@ -1,12 +1,12 @@
1
- import { signal as c, useSignal as v } from "@preact/signals";
2
- import { useRef as D, useEffect as p } from "preact/hooks";
3
- import { useLocation as w, useParams as S } from "wouter-preact";
4
- const y = c(!1);
5
- function P(e) {
1
+ import { signal as _, useSignal as d } from "@preact/signals";
2
+ import { useRef as g, useEffect as h } from "preact/hooks";
3
+ import { useLocation as v, useParams as D } from "wouter-preact";
4
+ const p = _(!1);
5
+ function m(e) {
6
6
  e.value !== null && typeof e.value == "object" && (e.value = { ...e.value });
7
7
  }
8
- function T(e) {
9
- const a = c(!1);
8
+ function P(e) {
9
+ const a = _(!1);
10
10
  if (typeof window > "u")
11
11
  return { data: {
12
12
  get value() {
@@ -14,50 +14,50 @@ function T(e) {
14
14
  }
15
15
  }, loading: a };
16
16
  const t = window.__PAGE_DATA__, n = e && t?.[e] ? t[e] : null;
17
- return { data: c(n), loading: a };
17
+ return { data: _(n), loading: a };
18
18
  }
19
- function E(e, a) {
19
+ function T(e, a) {
20
20
  let t, n;
21
21
  Array.isArray(e) ? n = e : (t = e, n = a);
22
22
  let r = null;
23
23
  if (typeof window > "u" && t) {
24
- const u = globalThis.__veloServerData?.getStore?.();
25
- u?.[t] && (r = u[t]);
24
+ const c = globalThis.__veloServerData?.getStore?.();
25
+ c?.[t] && (r = c[t]);
26
26
  }
27
27
  if (typeof window < "u" && t) {
28
28
  const o = window.__PAGE_DATA__;
29
29
  o?.[t] && (r = o[t], delete o[t]);
30
30
  }
31
- const _ = v(r), i = v(!1), f = () => {
31
+ const u = d(r), i = d(!1), l = () => {
32
32
  if (typeof window > "u" || !t) return;
33
33
  const o = window.location.pathname;
34
34
  i.value = !0;
35
- const d = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${o === "/" ? "" : o}/index.json` : (() => {
35
+ const w = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${o === "/" ? "" : o}/index.json` : (() => {
36
36
  const s = new URLSearchParams(window.location.search);
37
37
  return s.set("_data", "1"), `${o}?${s.toString()}`;
38
- })(), g = d.includes("?") ? "&" : "?", h = typeof __VELO_BUILD_HASH__ < "u" ? `${g}v=${__VELO_BUILD_HASH__}` : "";
39
- fetch(`${d}${h}`).then((s) => s.json()).then((s) => {
40
- typeof __VELO_BUILD_HASH__ < "u" && s.__buildHash && s.__buildHash !== __VELO_BUILD_HASH__ && (y.value = !0), _.value = s[t], i.value = !1;
38
+ })();
39
+ fetch(w, { cache: "no-cache" }).then((s) => s.json()).then((s) => {
40
+ typeof __VELO_BUILD_HASH__ < "u" && s.__buildHash && s.__buildHash !== __VELO_BUILD_HASH__ && (p.value = !0), u.value = s[t], i.value = !1;
41
41
  }).catch(() => {
42
42
  i.value = !1;
43
43
  });
44
- }, l = D(r !== null);
45
- return p(() => {
46
- if (l.current) {
47
- l.current = !1;
44
+ }, f = g(r !== null);
45
+ return h(() => {
46
+ if (f.current) {
47
+ f.current = !1;
48
48
  return;
49
49
  }
50
- f();
51
- }, n ?? []), { data: _, loading: i, refetch: f };
50
+ l();
51
+ }, n ?? []), { data: u, loading: i, refetch: l };
52
52
  }
53
- function H() {
54
- const [, e] = w();
53
+ function L() {
54
+ const [, e] = v();
55
55
  return e;
56
56
  }
57
- function b() {
58
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : S();
57
+ function E() {
58
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : D();
59
59
  }
60
- function U() {
60
+ function b() {
61
61
  if (typeof window > "u")
62
62
  return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
63
63
  const e = window.__PAGE_DATA__;
@@ -68,16 +68,16 @@ function U() {
68
68
  t[r] = n;
69
69
  }), t;
70
70
  }
71
- function $() {
72
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (w(), window.location.pathname);
71
+ function H() {
72
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (v(), window.location.pathname);
73
73
  }
74
74
  export {
75
- T as Loader,
76
- y as __veloUpdatePending,
77
- P as touch,
78
- E as useLoader,
79
- H as useNavigate,
80
- b as useParams,
81
- $ as usePathname,
82
- U as useQuery
75
+ P as Loader,
76
+ p as __veloUpdatePending,
77
+ m as touch,
78
+ T as useLoader,
79
+ L as useNavigate,
80
+ E as useParams,
81
+ H as usePathname,
82
+ b as useQuery
83
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [