@lolyjs/core 0.1.0-alpha.9 → 0.2.0-alpha.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/README.md +467 -325
- package/dist/bootstrap-BiCQmSkx.d.mts +50 -0
- package/dist/bootstrap-BiCQmSkx.d.ts +50 -0
- package/dist/cli.cjs +98 -20
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +98 -20
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +165 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -35
- package/dist/index.d.ts +2 -35
- package/dist/index.js +165 -159
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.cjs +5 -5
- package/dist/react/hooks.cjs.map +1 -1
- package/dist/react/hooks.d.mts +13 -3
- package/dist/react/hooks.d.ts +13 -3
- package/dist/react/hooks.js +5 -5
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/sockets.cjs +4 -1
- package/dist/react/sockets.cjs.map +1 -1
- package/dist/react/sockets.js +4 -1
- package/dist/react/sockets.js.map +1 -1
- package/dist/runtime.cjs +87 -161
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.mts +3 -45
- package/dist/runtime.d.ts +3 -45
- package/dist/runtime.js +83 -161
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -4
package/dist/react/hooks.cjs
CHANGED
|
@@ -47,8 +47,8 @@ var useBroadcastChannel = (channelName) => {
|
|
|
47
47
|
|
|
48
48
|
// modules/react/hooks/usePageProps/index.ts
|
|
49
49
|
var import_react2 = require("react");
|
|
50
|
-
|
|
51
|
-
const [
|
|
50
|
+
function usePageProps() {
|
|
51
|
+
const [state, setState] = (0, import_react2.useState)(() => {
|
|
52
52
|
if (typeof window !== "undefined" && window?.__FW_DATA__) {
|
|
53
53
|
const data = window.__FW_DATA__;
|
|
54
54
|
return {
|
|
@@ -65,7 +65,7 @@ var usePageProps = () => {
|
|
|
65
65
|
const handleDataRefresh = () => {
|
|
66
66
|
if (window?.__FW_DATA__) {
|
|
67
67
|
const data = window.__FW_DATA__;
|
|
68
|
-
|
|
68
|
+
setState({
|
|
69
69
|
params: data.params || {},
|
|
70
70
|
props: data.props || {}
|
|
71
71
|
});
|
|
@@ -76,8 +76,8 @@ var usePageProps = () => {
|
|
|
76
76
|
window.removeEventListener("fw-data-refresh", handleDataRefresh);
|
|
77
77
|
};
|
|
78
78
|
}, []);
|
|
79
|
-
return props;
|
|
80
|
-
}
|
|
79
|
+
return { params: state.params, props: state.props };
|
|
80
|
+
}
|
|
81
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
82
|
0 && (module.exports = {
|
|
83
83
|
useBroadcastChannel,
|
package/dist/react/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../modules/react/hooks/index.ts","../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/usePageProps/index.ts"],"sourcesContent":["export { useBroadcastChannel } from \"./useBroadcastChannel\";\r\nexport { usePageProps } from \"./usePageProps\";\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\n/**\r\n * Hook to access page props and route parameters.\r\n *\r\n * Reads initial data from window.__FW_DATA__ set during SSR.\r\n * Automatically updates when `revalidate()` is called.\r\n *\r\n * @returns Object containing params and props\r\n */\r\nexport
|
|
1
|
+
{"version":3,"sources":["../../modules/react/hooks/index.ts","../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/usePageProps/index.ts"],"sourcesContent":["export { useBroadcastChannel } from \"./useBroadcastChannel\";\r\nexport { usePageProps } from \"./usePageProps\";\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\n/**\r\n * Hook to access page props and route parameters.\r\n *\r\n * Reads initial data from window.__FW_DATA__ set during SSR.\r\n * Automatically updates when `revalidate()` is called.\r\n *\r\n * @template P - Type for page props (default: any)\r\n * @template T - Type for route params (default: any)\r\n * @returns Object containing params and props\r\n *\r\n * @example\r\n * // With props type only\r\n * const { props } = usePageProps<{ title: string }>();\r\n *\r\n * @example\r\n * // With both props and params types\r\n * const { props, params } = usePageProps<{ title: string }, { id: string }>();\r\n */\r\nexport function usePageProps<P = any, T = any>(): { params: T, props: P } {\r\n const [state, setState] = useState<{ params: T, props: P }>(() => {\r\n // Initialize with current data if available\r\n if (typeof window !== \"undefined\" && (window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n return {\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n };\r\n }\r\n return {\r\n params: {} as T,\r\n props: {} as P,\r\n };\r\n });\r\n\r\n useEffect(() => {\r\n // Listen for data refresh events (from revalidate() or navigation)\r\n const handleDataRefresh = () => {\r\n if ((window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n setState({\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n });\r\n }\r\n };\r\n\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }, []);\r\n\r\n return { params: state.params as T, props: state.props as P };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2C;AAEpC,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,IAAI;AAC3C,QAAM,UAAU,IAAI,iBAAiB,WAAW;AAEhD,8BAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,cAAc,CAAC,QAAiB;AACpC,YAAQ,YAAY,GAAG;AAAA,EACzB;AAEA,SAAO,EAAE,SAAS,YAAY;AAChC;;;ACxBA,IAAAA,gBAA2C;AAoBpC,SAAS,eAA0D;AACxE,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,MAAM;AAEhE,QAAI,OAAO,WAAW,eAAgB,QAAgB,aAAa;AACjE,YAAM,OAAQ,OAAe;AAC7B,aAAO;AAAA,QACL,QAAQ,KAAK,UAAU,CAAC;AAAA,QACxB,OAAO,KAAK,SAAS,CAAC;AAAA,MACxB;AAAA,IACF;AACA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,OAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AAED,+BAAU,MAAM;AAEd,UAAM,oBAAoB,MAAM;AAC9B,UAAK,QAAgB,aAAa;AAChC,cAAM,OAAQ,OAAe;AAC7B,iBAAS;AAAA,UACP,QAAQ,KAAK,UAAU,CAAC;AAAA,UACxB,OAAO,KAAK,SAAS,CAAC;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO,iBAAiB,mBAAmB,iBAAiB;AAE5D,WAAO,MAAM;AACX,aAAO,oBAAoB,mBAAmB,iBAAiB;AAAA,IACjE;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,EAAE,QAAQ,MAAM,QAAa,OAAO,MAAM,MAAW;AAC9D;","names":["import_react"]}
|
package/dist/react/hooks.d.mts
CHANGED
|
@@ -9,11 +9,21 @@ declare const useBroadcastChannel: (channelName: string) => {
|
|
|
9
9
|
* Reads initial data from window.__FW_DATA__ set during SSR.
|
|
10
10
|
* Automatically updates when `revalidate()` is called.
|
|
11
11
|
*
|
|
12
|
+
* @template P - Type for page props (default: any)
|
|
13
|
+
* @template T - Type for route params (default: any)
|
|
12
14
|
* @returns Object containing params and props
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With props type only
|
|
18
|
+
* const { props } = usePageProps<{ title: string }>();
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With both props and params types
|
|
22
|
+
* const { props, params } = usePageProps<{ title: string }, { id: string }>();
|
|
13
23
|
*/
|
|
14
|
-
declare
|
|
15
|
-
params:
|
|
16
|
-
props:
|
|
24
|
+
declare function usePageProps<P = any, T = any>(): {
|
|
25
|
+
params: T;
|
|
26
|
+
props: P;
|
|
17
27
|
};
|
|
18
28
|
|
|
19
29
|
export { useBroadcastChannel, usePageProps };
|
package/dist/react/hooks.d.ts
CHANGED
|
@@ -9,11 +9,21 @@ declare const useBroadcastChannel: (channelName: string) => {
|
|
|
9
9
|
* Reads initial data from window.__FW_DATA__ set during SSR.
|
|
10
10
|
* Automatically updates when `revalidate()` is called.
|
|
11
11
|
*
|
|
12
|
+
* @template P - Type for page props (default: any)
|
|
13
|
+
* @template T - Type for route params (default: any)
|
|
12
14
|
* @returns Object containing params and props
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // With props type only
|
|
18
|
+
* const { props } = usePageProps<{ title: string }>();
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // With both props and params types
|
|
22
|
+
* const { props, params } = usePageProps<{ title: string }, { id: string }>();
|
|
13
23
|
*/
|
|
14
|
-
declare
|
|
15
|
-
params:
|
|
16
|
-
props:
|
|
24
|
+
declare function usePageProps<P = any, T = any>(): {
|
|
25
|
+
params: T;
|
|
26
|
+
props: P;
|
|
17
27
|
};
|
|
18
28
|
|
|
19
29
|
export { useBroadcastChannel, usePageProps };
|
package/dist/react/hooks.js
CHANGED
|
@@ -20,8 +20,8 @@ var useBroadcastChannel = (channelName) => {
|
|
|
20
20
|
|
|
21
21
|
// modules/react/hooks/usePageProps/index.ts
|
|
22
22
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
23
|
-
|
|
24
|
-
const [
|
|
23
|
+
function usePageProps() {
|
|
24
|
+
const [state, setState] = useState2(() => {
|
|
25
25
|
if (typeof window !== "undefined" && window?.__FW_DATA__) {
|
|
26
26
|
const data = window.__FW_DATA__;
|
|
27
27
|
return {
|
|
@@ -38,7 +38,7 @@ var usePageProps = () => {
|
|
|
38
38
|
const handleDataRefresh = () => {
|
|
39
39
|
if (window?.__FW_DATA__) {
|
|
40
40
|
const data = window.__FW_DATA__;
|
|
41
|
-
|
|
41
|
+
setState({
|
|
42
42
|
params: data.params || {},
|
|
43
43
|
props: data.props || {}
|
|
44
44
|
});
|
|
@@ -49,8 +49,8 @@ var usePageProps = () => {
|
|
|
49
49
|
window.removeEventListener("fw-data-refresh", handleDataRefresh);
|
|
50
50
|
};
|
|
51
51
|
}, []);
|
|
52
|
-
return props;
|
|
53
|
-
}
|
|
52
|
+
return { params: state.params, props: state.props };
|
|
53
|
+
}
|
|
54
54
|
export {
|
|
55
55
|
useBroadcastChannel,
|
|
56
56
|
usePageProps
|
package/dist/react/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/usePageProps/index.ts"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\n/**\r\n * Hook to access page props and route parameters.\r\n *\r\n * Reads initial data from window.__FW_DATA__ set during SSR.\r\n * Automatically updates when `revalidate()` is called.\r\n *\r\n * @returns Object containing params and props\r\n */\r\nexport
|
|
1
|
+
{"version":3,"sources":["../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/usePageProps/index.ts"],"sourcesContent":["import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\n/**\r\n * Hook to access page props and route parameters.\r\n *\r\n * Reads initial data from window.__FW_DATA__ set during SSR.\r\n * Automatically updates when `revalidate()` is called.\r\n *\r\n * @template P - Type for page props (default: any)\r\n * @template T - Type for route params (default: any)\r\n * @returns Object containing params and props\r\n *\r\n * @example\r\n * // With props type only\r\n * const { props } = usePageProps<{ title: string }>();\r\n *\r\n * @example\r\n * // With both props and params types\r\n * const { props, params } = usePageProps<{ title: string }, { id: string }>();\r\n */\r\nexport function usePageProps<P = any, T = any>(): { params: T, props: P } {\r\n const [state, setState] = useState<{ params: T, props: P }>(() => {\r\n // Initialize with current data if available\r\n if (typeof window !== \"undefined\" && (window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n return {\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n };\r\n }\r\n return {\r\n params: {} as T,\r\n props: {} as P,\r\n };\r\n });\r\n\r\n useEffect(() => {\r\n // Listen for data refresh events (from revalidate() or navigation)\r\n const handleDataRefresh = () => {\r\n if ((window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n setState({\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n });\r\n }\r\n };\r\n\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }, []);\r\n\r\n return { params: state.params as T, props: state.props as P };\r\n};\r\n"],"mappings":";AAAA,SAAgB,WAAW,gBAAgB;AAEpC,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,UAAU,IAAI,iBAAiB,WAAW;AAEhD,YAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,cAAc,CAAC,QAAiB;AACpC,YAAQ,YAAY,GAAG;AAAA,EACzB;AAEA,SAAO,EAAE,SAAS,YAAY;AAChC;;;ACxBA,SAAgB,aAAAA,YAAW,YAAAC,iBAAgB;AAoBpC,SAAS,eAA0D;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkC,MAAM;AAEhE,QAAI,OAAO,WAAW,eAAgB,QAAgB,aAAa;AACjE,YAAM,OAAQ,OAAe;AAC7B,aAAO;AAAA,QACL,QAAQ,KAAK,UAAU,CAAC;AAAA,QACxB,OAAO,KAAK,SAAS,CAAC;AAAA,MACxB;AAAA,IACF;AACA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,OAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AAED,EAAAD,WAAU,MAAM;AAEd,UAAM,oBAAoB,MAAM;AAC9B,UAAK,QAAgB,aAAa;AAChC,cAAM,OAAQ,OAAe;AAC7B,iBAAS;AAAA,UACP,QAAQ,KAAK,UAAU,CAAC;AAAA,UACxB,OAAO,KAAK,SAAS,CAAC;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO,iBAAiB,mBAAmB,iBAAiB;AAE5D,WAAO,MAAM;AACX,aAAO,oBAAoB,mBAAmB,iBAAiB;AAAA,IACjE;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,EAAE,QAAQ,MAAM,QAAa,OAAO,MAAM,MAAW;AAC9D;","names":["useEffect","useState"]}
|
package/dist/react/sockets.cjs
CHANGED
|
@@ -25,7 +25,10 @@ __export(sockets_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(sockets_exports);
|
|
26
26
|
var import_socket = require("socket.io-client");
|
|
27
27
|
var lolySocket = (namespace, opts) => {
|
|
28
|
-
const baseUrl = process
|
|
28
|
+
const baseUrl = process?.env?.PUBLIC_WS_BASE_URL || window.location.origin;
|
|
29
|
+
if (!process?.env?.PUBLIC_WS_BASE_URL) {
|
|
30
|
+
console.warn("[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.");
|
|
31
|
+
}
|
|
29
32
|
const normalizedNamespace = namespace.startsWith("/") ? namespace : `/${namespace}`;
|
|
30
33
|
const fullUrl = `${baseUrl}${normalizedNamespace}`;
|
|
31
34
|
const socket = (0, import_socket.io)(fullUrl, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n const baseUrl = process.env.PUBLIC_WS_BASE_URL
|
|
1
|
+
{"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n const baseUrl = process?.env?.PUBLIC_WS_BASE_URL || window.location.origin;\r\n\r\n if(!process?.env?.PUBLIC_WS_BASE_URL) {\r\n console.warn(\"[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.\");\r\n }\r\n\r\n // Normalize namespace to always start with '/'\r\n const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n\r\n // In Socket.IO, when using a custom path, the namespace is specified in the URL:\r\n // baseUrl + namespace. The path '/wss' is the HTTP route where Socket.IO listens.\r\n const fullUrl = `${baseUrl}${normalizedNamespace}`;\r\n\r\n const socket = io(fullUrl, {\r\n path: \"/wss\",\r\n transports: [\"websocket\", \"polling\"],\r\n autoConnect: true,\r\n ...opts,\r\n });\r\n\r\n return socket;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0D;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AACX,QAAM,UAAU,SAAS,KAAK,sBAAsB,OAAO,SAAS;AAEpE,MAAG,CAAC,SAAS,KAAK,oBAAoB;AACpC,YAAQ,KAAK,4EAA4E;AAAA,EAC3F;AAGA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAIjF,QAAM,UAAU,GAAG,OAAO,GAAG,mBAAmB;AAEhD,QAAM,aAAS,kBAAG,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}
|
package/dist/react/sockets.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// modules/react/sockets/index.ts
|
|
2
2
|
import { io } from "socket.io-client";
|
|
3
3
|
var lolySocket = (namespace, opts) => {
|
|
4
|
-
const baseUrl = process
|
|
4
|
+
const baseUrl = process?.env?.PUBLIC_WS_BASE_URL || window.location.origin;
|
|
5
|
+
if (!process?.env?.PUBLIC_WS_BASE_URL) {
|
|
6
|
+
console.warn("[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.");
|
|
7
|
+
}
|
|
5
8
|
const normalizedNamespace = namespace.startsWith("/") ? namespace : `/${namespace}`;
|
|
6
9
|
const fullUrl = `${baseUrl}${normalizedNamespace}`;
|
|
7
10
|
const socket = io(fullUrl, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n const baseUrl = process.env.PUBLIC_WS_BASE_URL
|
|
1
|
+
{"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n const baseUrl = process?.env?.PUBLIC_WS_BASE_URL || window.location.origin;\r\n\r\n if(!process?.env?.PUBLIC_WS_BASE_URL) {\r\n console.warn(\"[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.\");\r\n }\r\n\r\n // Normalize namespace to always start with '/'\r\n const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n\r\n // In Socket.IO, when using a custom path, the namespace is specified in the URL:\r\n // baseUrl + namespace. The path '/wss' is the HTTP route where Socket.IO listens.\r\n const fullUrl = `${baseUrl}${normalizedNamespace}`;\r\n\r\n const socket = io(fullUrl, {\r\n path: \"/wss\",\r\n transports: [\"websocket\", \"polling\"],\r\n autoConnect: true,\r\n ...opts,\r\n });\r\n\r\n return socket;\r\n};\r\n"],"mappings":";AAAA,SAAS,UAAiD;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AACX,QAAM,UAAU,SAAS,KAAK,sBAAsB,OAAO,SAAS;AAEpE,MAAG,CAAC,SAAS,KAAK,oBAAoB;AACpC,YAAQ,KAAK,4EAA4E;AAAA,EAC3F;AAGA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAIjF,QAAM,UAAU,GAAG,OAAO,GAAG,mBAAmB;AAEhD,QAAM,SAAS,GAAG,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}
|