@devfellowship/components 0.1.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/dist/hooks.cjs ADDED
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/hooks/index.ts
31
+ var hooks_exports = {};
32
+ __export(hooks_exports, {
33
+ AuthContext: () => AuthContext,
34
+ toast: () => toast,
35
+ useAuth: () => useAuth,
36
+ useIsMobile: () => useIsMobile,
37
+ useSession: () => useSession,
38
+ useToast: () => useToast
39
+ });
40
+ module.exports = __toCommonJS(hooks_exports);
41
+
42
+ // src/hooks/use-mobile.ts
43
+ var React = __toESM(require("react"), 1);
44
+ var MOBILE_BREAKPOINT = 768;
45
+ function useIsMobile() {
46
+ const [isMobile, setIsMobile] = React.useState(void 0);
47
+ React.useEffect(() => {
48
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
49
+ const onChange = () => {
50
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
51
+ };
52
+ mql.addEventListener("change", onChange);
53
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
54
+ return () => mql.removeEventListener("change", onChange);
55
+ }, []);
56
+ return !!isMobile;
57
+ }
58
+
59
+ // src/hooks/use-toast.ts
60
+ var React2 = __toESM(require("react"), 1);
61
+ var TOAST_LIMIT = 1;
62
+ var TOAST_REMOVE_DELAY = 1e6;
63
+ var actionTypes = {
64
+ ADD_TOAST: "ADD_TOAST",
65
+ UPDATE_TOAST: "UPDATE_TOAST",
66
+ DISMISS_TOAST: "DISMISS_TOAST",
67
+ REMOVE_TOAST: "REMOVE_TOAST"
68
+ };
69
+ var count = 0;
70
+ function genId() {
71
+ count = (count + 1) % Number.MAX_SAFE_INTEGER;
72
+ return count.toString();
73
+ }
74
+ var toastTimeouts = /* @__PURE__ */ new Map();
75
+ var addToRemoveQueue = (toastId) => {
76
+ if (toastTimeouts.has(toastId)) return;
77
+ const timeout = setTimeout(() => {
78
+ toastTimeouts.delete(toastId);
79
+ dispatch({ type: actionTypes.REMOVE_TOAST, toastId });
80
+ }, TOAST_REMOVE_DELAY);
81
+ toastTimeouts.set(toastId, timeout);
82
+ };
83
+ var reducer = (state, action) => {
84
+ switch (action.type) {
85
+ case actionTypes.ADD_TOAST:
86
+ return {
87
+ ...state,
88
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
89
+ };
90
+ case actionTypes.UPDATE_TOAST:
91
+ return {
92
+ ...state,
93
+ toasts: state.toasts.map(
94
+ (t) => t.id === action.toast.id ? { ...t, ...action.toast } : t
95
+ )
96
+ };
97
+ case actionTypes.DISMISS_TOAST: {
98
+ const { toastId } = action;
99
+ if (toastId) {
100
+ addToRemoveQueue(toastId);
101
+ } else {
102
+ state.toasts.forEach((t) => addToRemoveQueue(t.id));
103
+ }
104
+ return {
105
+ ...state,
106
+ toasts: state.toasts.map(
107
+ (t) => t.id === toastId || toastId === void 0 ? { ...t, open: false } : t
108
+ )
109
+ };
110
+ }
111
+ case actionTypes.REMOVE_TOAST:
112
+ if (action.toastId === void 0) return { ...state, toasts: [] };
113
+ return {
114
+ ...state,
115
+ toasts: state.toasts.filter((t) => t.id !== action.toastId)
116
+ };
117
+ }
118
+ };
119
+ var listeners = [];
120
+ var memoryState = { toasts: [] };
121
+ function dispatch(action) {
122
+ memoryState = reducer(memoryState, action);
123
+ listeners.forEach((listener) => listener(memoryState));
124
+ }
125
+ function toast(props) {
126
+ const id = genId();
127
+ const update = (p) => dispatch({ type: actionTypes.UPDATE_TOAST, toast: { ...p, id } });
128
+ const dismiss = () => dispatch({ type: actionTypes.DISMISS_TOAST, toastId: id });
129
+ dispatch({
130
+ type: actionTypes.ADD_TOAST,
131
+ toast: { ...props, id, open: true, onOpenChange: (open) => {
132
+ if (!open) dismiss();
133
+ } }
134
+ });
135
+ return { id, dismiss, update };
136
+ }
137
+ function useToast() {
138
+ const [state, setState] = React2.useState(memoryState);
139
+ React2.useEffect(() => {
140
+ listeners.push(setState);
141
+ return () => {
142
+ const idx = listeners.indexOf(setState);
143
+ if (idx > -1) listeners.splice(idx, 1);
144
+ };
145
+ }, []);
146
+ return {
147
+ ...state,
148
+ toast,
149
+ dismiss: (toastId) => dispatch({ type: actionTypes.DISMISS_TOAST, toastId })
150
+ };
151
+ }
152
+
153
+ // src/hooks/use-auth.tsx
154
+ var import_react = require("react");
155
+ var import_jsx_runtime = require("react/jsx-runtime");
156
+ var AuthContext = (0, import_react.createContext)(void 0);
157
+ var useAuth = () => {
158
+ const ctx = (0, import_react.useContext)(AuthContext);
159
+ if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
160
+ return ctx;
161
+ };
162
+ var useSession = () => {
163
+ const { session } = useAuth();
164
+ return session;
165
+ };
166
+ // Annotate the CommonJS export names for ESM import in node:
167
+ 0 && (module.exports = {
168
+ AuthContext,
169
+ toast,
170
+ useAuth,
171
+ useIsMobile,
172
+ useSession,
173
+ useToast
174
+ });
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ export { d as AuthContext, A as AuthContextType, U as UserProfile, u as useAuth, c as useSession } from './use-auth-DdapDv2H.cjs';
3
+ import 'react/jsx-runtime';
4
+ import '@supabase/supabase-js';
5
+
6
+ declare function useIsMobile(): boolean;
7
+
8
+ /**
9
+ * use-toast — toast notification hook
10
+ * Ported from shadcn/ui toast pattern (identical across dfl apps).
11
+ */
12
+
13
+ type ToastVariant = "default" | "destructive";
14
+ interface ToastProps {
15
+ id: string;
16
+ title?: React.ReactNode;
17
+ description?: React.ReactNode;
18
+ variant?: ToastVariant;
19
+ duration?: number;
20
+ open?: boolean;
21
+ onOpenChange?: (open: boolean) => void;
22
+ }
23
+ type ToastInput = Omit<ToastProps, "id">;
24
+ declare function toast(props: ToastInput): {
25
+ id: string;
26
+ dismiss: () => void;
27
+ update: (p: ToastInput) => void;
28
+ };
29
+ declare function useToast(): {
30
+ toast: typeof toast;
31
+ dismiss: (toastId?: string) => void;
32
+ toasts: ToastProps[];
33
+ };
34
+
35
+ export { type ToastProps, type ToastVariant, toast, useIsMobile, useToast };
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ export { d as AuthContext, A as AuthContextType, U as UserProfile, u as useAuth, c as useSession } from './use-auth-DdapDv2H.js';
3
+ import 'react/jsx-runtime';
4
+ import '@supabase/supabase-js';
5
+
6
+ declare function useIsMobile(): boolean;
7
+
8
+ /**
9
+ * use-toast — toast notification hook
10
+ * Ported from shadcn/ui toast pattern (identical across dfl apps).
11
+ */
12
+
13
+ type ToastVariant = "default" | "destructive";
14
+ interface ToastProps {
15
+ id: string;
16
+ title?: React.ReactNode;
17
+ description?: React.ReactNode;
18
+ variant?: ToastVariant;
19
+ duration?: number;
20
+ open?: boolean;
21
+ onOpenChange?: (open: boolean) => void;
22
+ }
23
+ type ToastInput = Omit<ToastProps, "id">;
24
+ declare function toast(props: ToastInput): {
25
+ id: string;
26
+ dismiss: () => void;
27
+ update: (p: ToastInput) => void;
28
+ };
29
+ declare function useToast(): {
30
+ toast: typeof toast;
31
+ dismiss: (toastId?: string) => void;
32
+ toasts: ToastProps[];
33
+ };
34
+
35
+ export { type ToastProps, type ToastVariant, toast, useIsMobile, useToast };
package/dist/hooks.js ADDED
@@ -0,0 +1,140 @@
1
+ // src/hooks/use-mobile.ts
2
+ import * as React from "react";
3
+ var MOBILE_BREAKPOINT = 768;
4
+ function useIsMobile() {
5
+ const [isMobile, setIsMobile] = React.useState(void 0);
6
+ React.useEffect(() => {
7
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
8
+ const onChange = () => {
9
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
10
+ };
11
+ mql.addEventListener("change", onChange);
12
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
13
+ return () => mql.removeEventListener("change", onChange);
14
+ }, []);
15
+ return !!isMobile;
16
+ }
17
+
18
+ // src/hooks/use-toast.ts
19
+ import * as React2 from "react";
20
+ var TOAST_LIMIT = 1;
21
+ var TOAST_REMOVE_DELAY = 1e6;
22
+ var actionTypes = {
23
+ ADD_TOAST: "ADD_TOAST",
24
+ UPDATE_TOAST: "UPDATE_TOAST",
25
+ DISMISS_TOAST: "DISMISS_TOAST",
26
+ REMOVE_TOAST: "REMOVE_TOAST"
27
+ };
28
+ var count = 0;
29
+ function genId() {
30
+ count = (count + 1) % Number.MAX_SAFE_INTEGER;
31
+ return count.toString();
32
+ }
33
+ var toastTimeouts = /* @__PURE__ */ new Map();
34
+ var addToRemoveQueue = (toastId) => {
35
+ if (toastTimeouts.has(toastId)) return;
36
+ const timeout = setTimeout(() => {
37
+ toastTimeouts.delete(toastId);
38
+ dispatch({ type: actionTypes.REMOVE_TOAST, toastId });
39
+ }, TOAST_REMOVE_DELAY);
40
+ toastTimeouts.set(toastId, timeout);
41
+ };
42
+ var reducer = (state, action) => {
43
+ switch (action.type) {
44
+ case actionTypes.ADD_TOAST:
45
+ return {
46
+ ...state,
47
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
48
+ };
49
+ case actionTypes.UPDATE_TOAST:
50
+ return {
51
+ ...state,
52
+ toasts: state.toasts.map(
53
+ (t) => t.id === action.toast.id ? { ...t, ...action.toast } : t
54
+ )
55
+ };
56
+ case actionTypes.DISMISS_TOAST: {
57
+ const { toastId } = action;
58
+ if (toastId) {
59
+ addToRemoveQueue(toastId);
60
+ } else {
61
+ state.toasts.forEach((t) => addToRemoveQueue(t.id));
62
+ }
63
+ return {
64
+ ...state,
65
+ toasts: state.toasts.map(
66
+ (t) => t.id === toastId || toastId === void 0 ? { ...t, open: false } : t
67
+ )
68
+ };
69
+ }
70
+ case actionTypes.REMOVE_TOAST:
71
+ if (action.toastId === void 0) return { ...state, toasts: [] };
72
+ return {
73
+ ...state,
74
+ toasts: state.toasts.filter((t) => t.id !== action.toastId)
75
+ };
76
+ }
77
+ };
78
+ var listeners = [];
79
+ var memoryState = { toasts: [] };
80
+ function dispatch(action) {
81
+ memoryState = reducer(memoryState, action);
82
+ listeners.forEach((listener) => listener(memoryState));
83
+ }
84
+ function toast(props) {
85
+ const id = genId();
86
+ const update = (p) => dispatch({ type: actionTypes.UPDATE_TOAST, toast: { ...p, id } });
87
+ const dismiss = () => dispatch({ type: actionTypes.DISMISS_TOAST, toastId: id });
88
+ dispatch({
89
+ type: actionTypes.ADD_TOAST,
90
+ toast: { ...props, id, open: true, onOpenChange: (open) => {
91
+ if (!open) dismiss();
92
+ } }
93
+ });
94
+ return { id, dismiss, update };
95
+ }
96
+ function useToast() {
97
+ const [state, setState] = React2.useState(memoryState);
98
+ React2.useEffect(() => {
99
+ listeners.push(setState);
100
+ return () => {
101
+ const idx = listeners.indexOf(setState);
102
+ if (idx > -1) listeners.splice(idx, 1);
103
+ };
104
+ }, []);
105
+ return {
106
+ ...state,
107
+ toast,
108
+ dismiss: (toastId) => dispatch({ type: actionTypes.DISMISS_TOAST, toastId })
109
+ };
110
+ }
111
+
112
+ // src/hooks/use-auth.tsx
113
+ import {
114
+ createContext,
115
+ useContext,
116
+ useState as useState3,
117
+ useEffect as useEffect3,
118
+ useCallback,
119
+ useMemo,
120
+ useRef
121
+ } from "react";
122
+ import { jsx } from "react/jsx-runtime";
123
+ var AuthContext = createContext(void 0);
124
+ var useAuth = () => {
125
+ const ctx = useContext(AuthContext);
126
+ if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
127
+ return ctx;
128
+ };
129
+ var useSession = () => {
130
+ const { session } = useAuth();
131
+ return session;
132
+ };
133
+ export {
134
+ AuthContext,
135
+ toast,
136
+ useAuth,
137
+ useIsMobile,
138
+ useSession,
139
+ useToast
140
+ };