@mauroandre/velojs 0.0.45 → 0.0.46

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.
Files changed (2) hide show
  1. package/dist/hooks.js +68 -71
  2. package/package.json +1 -1
package/dist/hooks.js CHANGED
@@ -1,39 +1,39 @@
1
- import { signal as w, useSignal as c } from "@preact/signals";
2
- import { useEffect as E, useRef as S } from "preact/hooks";
3
- import { useLocation as b, useParams as A } from "wouter-preact";
4
- import { refetchModule as m, loaderLoading as L, loaderEntry as N } from "./loader-store.js";
5
- import { __veloUpdatePending as Q } from "./loader-store.js";
6
- function R(e) {
1
+ import { signal as S, useSignal as c } from "@preact/signals";
2
+ import { useEffect as E, useRef as w } from "preact/hooks";
3
+ import { useLocation as D, useParams as $, useSearch as C } from "wouter-preact";
4
+ import { refetchModule as L, loaderLoading as m, loaderEntry as N } from "./loader-store.js";
5
+ import { __veloUpdatePending as z } from "./loader-store.js";
6
+ function U(e) {
7
7
  const n = e.value;
8
8
  n === null || typeof n != "object" || (e.value = Array.isArray(n) ? [...n] : { ...n });
9
9
  }
10
- function U(e) {
10
+ function W(e) {
11
11
  return typeof window > "u" ? {
12
12
  data: {
13
13
  get value() {
14
14
  return e ? globalThis.__veloServerData?.getStore?.()?.[e] ?? null : null;
15
15
  }
16
16
  },
17
- loading: w(!1),
17
+ loading: S(!1),
18
18
  refetch: () => {
19
19
  }
20
20
  } : e ? {
21
21
  data: N(e),
22
- loading: L(e),
23
- refetch: () => m(e)
24
- } : { data: w(null), loading: w(!1), refetch: () => {
22
+ loading: m(e),
23
+ refetch: () => L(e)
24
+ } : { data: S(null), loading: S(!1), refetch: () => {
25
25
  } };
26
26
  }
27
- function W(e, n) {
27
+ function j(e, n) {
28
28
  let t, r;
29
29
  if (Array.isArray(e) ? r = e : (t = e, r = n), typeof window > "u") {
30
- let _ = null;
30
+ let g = null;
31
31
  if (t) {
32
32
  const h = globalThis.__veloServerData?.getStore?.();
33
- h?.[t] && (_ = h[t]);
33
+ h?.[t] && (g = h[t]);
34
34
  }
35
35
  return {
36
- data: c(_),
36
+ data: c(g),
37
37
  loading: c(!1),
38
38
  refetch: () => {
39
39
  }
@@ -42,108 +42,105 @@ function W(e, n) {
42
42
  if (!t)
43
43
  return { data: c(null), loading: c(!1), refetch: () => {
44
44
  } };
45
- const a = N(t), o = L(t), u = () => m(t), d = S(!0);
45
+ const o = N(t), a = m(t), u = () => L(t), d = w(!0);
46
46
  return E(() => {
47
- d.current && (d.current = !1, a.value !== null) || u();
48
- }, r ?? []), { data: a, loading: o, refetch: u };
47
+ d.current && (d.current = !1, o.value !== null) || u();
48
+ }, r ?? []), { data: o, loading: a, refetch: u };
49
49
  }
50
- function q() {
51
- const [, e] = b();
50
+ function J() {
51
+ const [, e] = D();
52
52
  return e;
53
53
  }
54
- function j() {
55
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : A();
54
+ function M() {
55
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : $();
56
56
  }
57
- function G() {
57
+ function q() {
58
58
  if (typeof window > "u")
59
59
  return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
60
- const e = window.__PAGE_DATA__;
61
- if (e?.__query)
62
- return e.__query;
63
- const n = new URLSearchParams(window.location.search), t = {};
64
- return n.forEach((r, a) => {
65
- t[a] = r;
66
- }), t;
60
+ const e = C(), n = {};
61
+ return new URLSearchParams(e).forEach((t, r) => {
62
+ n[r] = t;
63
+ }), n;
67
64
  }
68
- function J() {
69
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (b(), window.location.pathname);
65
+ function x() {
66
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (D(), window.location.pathname);
70
67
  }
71
- function M(e, n = {}) {
72
- const t = c(null), r = c(null), a = c(!1), o = c(null), { channel: u, enabled: d = !0 } = n;
68
+ function G(e, n = {}) {
69
+ const t = c(null), r = c(null), o = c(!1), a = c(null), { channel: u, enabled: d = !0 } = n;
73
70
  return E(() => {
74
71
  if (typeof window > "u" || !d) return;
75
72
  if (!e.__path) {
76
73
  console.warn("[velojs] useEventStream: stream has no __path");
77
74
  return;
78
75
  }
79
- t.value = null, r.value = null, a.value = !1, o.value = null;
80
- const _ = u ? `${e.__path}?channel=${encodeURIComponent(u)}` : e.__path, s = new EventSource(_);
76
+ t.value = null, r.value = null, o.value = !1, a.value = null;
77
+ const g = u ? `${e.__path}?channel=${encodeURIComponent(u)}` : e.__path, s = new EventSource(g);
81
78
  return s.addEventListener("snapshot", (h) => {
82
79
  try {
83
80
  r.value = JSON.parse(h.data);
84
- } catch (y) {
85
- o.value = y;
81
+ } catch (_) {
82
+ a.value = _;
86
83
  }
87
84
  }), s.addEventListener("message", (h) => {
88
85
  try {
89
86
  t.value = JSON.parse(h.data);
90
- } catch (y) {
91
- o.value = y;
87
+ } catch (_) {
88
+ a.value = _;
92
89
  }
93
90
  }), s.addEventListener("heartbeat", () => {
94
91
  }), s.addEventListener("close", () => {
95
- a.value = !0, s.close();
92
+ o.value = !0, s.close();
96
93
  }), s.addEventListener("error", () => {
97
- s.readyState === EventSource.CLOSED && (a.value = !0);
94
+ s.readyState === EventSource.CLOSED && (o.value = !0);
98
95
  }), () => {
99
96
  s.close();
100
97
  };
101
- }, [e, u, d]), { data: t, snapshot: r, closed: a, error: o };
98
+ }, [e, u, d]), { data: t, snapshot: r, closed: o, error: a };
102
99
  }
103
- function x(e, n = {}) {
104
- const t = c("connecting"), r = c(null), a = c(null), o = S(null), u = S([]), { channel: d, onMessage: _, onOpen: s, onClose: h, onError: y, enabled: D = !0 } = n;
100
+ function B(e, n = {}) {
101
+ const t = c("connecting"), r = c(null), o = c(null), a = w(null), u = w([]), { channel: d, onMessage: g, onOpen: s, onClose: h, onError: _, enabled: b = !0 } = n;
105
102
  return E(() => {
106
- if (typeof window > "u" || !D) return;
103
+ if (typeof window > "u" || !b) return;
107
104
  if (!e.__path) {
108
105
  console.warn("[velojs] useSocket: stub has no __path");
109
106
  return;
110
107
  }
111
- t.value = "connecting", r.value = null, a.value = null;
108
+ t.value = "connecting", r.value = null, o.value = null;
112
109
  const v = `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}`, i = d ? `${v}${e.__path}?channel=${encodeURIComponent(d)}` : `${v}${e.__path}`, f = new WebSocket(i);
113
- return f.binaryType = "arraybuffer", o.current = f, f.addEventListener("open", () => {
110
+ return f.binaryType = "arraybuffer", a.current = f, f.addEventListener("open", () => {
114
111
  t.value = "open";
115
112
  const l = u.current;
116
113
  u.current = [];
117
- for (const g of l)
114
+ for (const y of l)
118
115
  try {
119
- f.send(g);
116
+ f.send(y);
120
117
  } catch {
121
118
  }
122
119
  s?.();
123
120
  }), f.addEventListener("message", (l) => {
124
- let g;
121
+ let y;
125
122
  if (typeof l.data == "string")
126
- g = l.data;
123
+ y = l.data;
127
124
  else if (l.data instanceof ArrayBuffer)
128
- g = new Uint8Array(l.data);
125
+ y = new Uint8Array(l.data);
129
126
  else
130
127
  return;
131
- r.value = g, _?.(g);
128
+ r.value = y, g?.(y);
132
129
  }), f.addEventListener("close", (l) => {
133
- t.value = "closed", o.current = null, h?.(l);
130
+ t.value = "closed", a.current = null, h?.(l);
134
131
  }), f.addEventListener("error", (l) => {
135
- a.value = l, y?.(l);
132
+ o.value = l, _?.(l);
136
133
  }), () => {
137
- o.current = null;
134
+ a.current = null;
138
135
  try {
139
136
  (f.readyState === WebSocket.OPEN || f.readyState === WebSocket.CONNECTING) && f.close();
140
137
  } catch {
141
138
  }
142
139
  };
143
- }, [e.__path, d, D]), { send: (p) => {
140
+ }, [e.__path, d, b]), { send: (p) => {
144
141
  let v;
145
142
  typeof p == "string" || p instanceof Uint8Array ? v = p : v = JSON.stringify(p);
146
- const i = o.current;
143
+ const i = a.current;
147
144
  if (i && i.readyState === WebSocket.OPEN)
148
145
  try {
149
146
  i.send(v);
@@ -151,23 +148,23 @@ function x(e, n = {}) {
151
148
  }
152
149
  else i && i.readyState === WebSocket.CONNECTING && u.current.push(v);
153
150
  }, close: (p, v) => {
154
- const i = o.current;
151
+ const i = a.current;
155
152
  if (i)
156
153
  try {
157
154
  i.close(p, v);
158
155
  } catch {
159
156
  }
160
- }, status: t, lastMessage: r, error: a };
157
+ }, status: t, lastMessage: r, error: o };
161
158
  }
162
159
  export {
163
- U as Loader,
164
- Q as __veloUpdatePending,
165
- R as touch,
166
- M as useEventStream,
167
- W as useLoader,
168
- q as useNavigate,
169
- j as useParams,
170
- J as usePathname,
171
- G as useQuery,
172
- x as useSocket
160
+ W as Loader,
161
+ z as __veloUpdatePending,
162
+ U as touch,
163
+ G as useEventStream,
164
+ j as useLoader,
165
+ J as useNavigate,
166
+ M as useParams,
167
+ x as usePathname,
168
+ q as useQuery,
169
+ B as useSocket
173
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mauroandre/velojs",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "type": "module",
5
5
  "description": "Fullstack web framework built on Hono + Preact with Vite-powered AST transforms",
6
6
  "keywords": [