@sikka/hawa 0.30.26-next → 0.30.27-next

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,411 @@
1
+ "use client";
2
+
3
+ // hooks/useIsomorphicEffect.ts
4
+ import { useEffect, useLayoutEffect } from "react";
5
+ var useIsomorphicEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
6
+
7
+ // hooks/useDiscloser.ts
8
+ import { useState } from "react";
9
+
10
+ // hooks/useHover.ts
11
+ import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
12
+
13
+ // hooks/useToast.ts
14
+ import * as React3 from "react";
15
+ var TOAST_LIMIT = 5;
16
+ var TOAST_REMOVE_DELAY = 1e5;
17
+ var count = 0;
18
+ function genId() {
19
+ count = (count + 1) % Number.MAX_VALUE;
20
+ return count.toString();
21
+ }
22
+ var toastTimeouts = /* @__PURE__ */ new Map();
23
+ var addToRemoveQueue = (toastId) => {
24
+ if (toastTimeouts.has(toastId)) {
25
+ return;
26
+ }
27
+ const timeout = setTimeout(() => {
28
+ toastTimeouts.delete(toastId);
29
+ dispatch({ type: "REMOVE_TOAST", toastId });
30
+ }, TOAST_REMOVE_DELAY);
31
+ toastTimeouts.set(toastId, timeout);
32
+ };
33
+ var reducer = (state, action) => {
34
+ switch (action.type) {
35
+ case "ADD_TOAST":
36
+ return {
37
+ ...state,
38
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
39
+ };
40
+ case "UPDATE_TOAST":
41
+ return {
42
+ ...state,
43
+ toasts: state.toasts.map(
44
+ (t) => t.id === action.toast.id ? { ...t, ...action.toast } : t
45
+ )
46
+ };
47
+ case "DISMISS_TOAST": {
48
+ const { toastId } = action;
49
+ if (toastId) {
50
+ addToRemoveQueue(toastId);
51
+ } else {
52
+ state.toasts.forEach((toast2) => {
53
+ addToRemoveQueue(toast2.id);
54
+ });
55
+ }
56
+ return {
57
+ ...state,
58
+ toasts: state.toasts.map(
59
+ (t) => t.id === toastId || toastId === void 0 ? { ...t, open: false } : t
60
+ )
61
+ };
62
+ }
63
+ case "REMOVE_TOAST":
64
+ if (action.toastId === void 0) {
65
+ return { ...state, toasts: [] };
66
+ }
67
+ return {
68
+ ...state,
69
+ toasts: state.toasts.filter((t) => t.id !== action.toastId)
70
+ };
71
+ }
72
+ };
73
+ var listeners = [];
74
+ var memoryState = { toasts: [] };
75
+ function dispatch(action) {
76
+ memoryState = reducer(memoryState, action);
77
+ listeners.forEach((listener) => {
78
+ listener(memoryState);
79
+ });
80
+ }
81
+ function toast({ ...props }) {
82
+ const id = genId();
83
+ const update = (props2) => dispatch({ type: "UPDATE_TOAST", toast: { ...props2, id } });
84
+ const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
85
+ dispatch({
86
+ type: "ADD_TOAST",
87
+ toast: {
88
+ ...props,
89
+ id,
90
+ open: true,
91
+ onOpenChange: (open) => {
92
+ if (!open)
93
+ dismiss();
94
+ }
95
+ }
96
+ });
97
+ return { id, dismiss, update };
98
+ }
99
+ function useToast() {
100
+ const [state, setState] = React3.useState(memoryState);
101
+ React3.useEffect(() => {
102
+ listeners.push(setState);
103
+ return () => {
104
+ const index = listeners.indexOf(setState);
105
+ if (index > -1) {
106
+ listeners.splice(index, 1);
107
+ }
108
+ };
109
+ }, [state]);
110
+ return {
111
+ ...state,
112
+ toast,
113
+ dismiss: (toastId) => dispatch({ type: "DISMISS_TOAST", toastId })
114
+ };
115
+ }
116
+
117
+ // hooks/useCarousel.ts
118
+ import { useState as useState4, useRef as useRef2 } from "react";
119
+
120
+ // hooks/useDialogCarousel.ts
121
+ import { useEffect as useEffect4, useState as useState5 } from "react";
122
+ import AutoHeight from "embla-carousel-auto-height";
123
+ import useEmblaCarousel from "embla-carousel-react";
124
+ var useDialogCarousel = (options) => {
125
+ const [emblaRef, emblaApi] = useEmblaCarousel(
126
+ { loop: false, watchDrag: false, startIndex: 0, ...options },
127
+ [AutoHeight({ destroyHeight: "fit", active: true })]
128
+ );
129
+ const [canScrollPrev, setCanScrollPrev] = useState5(false);
130
+ const checkCanScrollPrev = () => {
131
+ if (emblaApi) {
132
+ setCanScrollPrev(emblaApi.canScrollPrev());
133
+ }
134
+ };
135
+ const nextStep = () => {
136
+ if (emblaApi) {
137
+ console.log("going to NEXT \u{1F449}");
138
+ emblaApi.scrollNext();
139
+ }
140
+ };
141
+ const prevStep = () => {
142
+ if (emblaApi) {
143
+ console.log("going to BACK \u{1F448}");
144
+ emblaApi.scrollPrev();
145
+ }
146
+ };
147
+ useEffect4(() => {
148
+ checkCanScrollPrev();
149
+ emblaApi && emblaApi.on("select", checkCanScrollPrev);
150
+ return () => {
151
+ emblaApi && emblaApi.off("select", checkCanScrollPrev);
152
+ };
153
+ }, [emblaApi]);
154
+ return {
155
+ emblaRef,
156
+ emblaApi,
157
+ nextStep,
158
+ prevStep,
159
+ canScrollPrev
160
+ };
161
+ };
162
+
163
+ // hooks/useDialogSteps.ts
164
+ import { useState as useState6, useEffect as useEffect5, useRef as useRef3 } from "react";
165
+ var useMultiStepDialog = (initialStep, stepIds, setOpenDialog) => {
166
+ const [currentStep, setCurrentStep] = useState6(initialStep);
167
+ const [dialogHeight, setDialogHeight] = useState6(null);
168
+ const visibleStepRef = useRef3(null);
169
+ useEffect5(() => {
170
+ if (visibleStepRef.current) {
171
+ setDialogHeight(visibleStepRef.current.offsetHeight);
172
+ }
173
+ }, [currentStep, setOpenDialog]);
174
+ const handleNext = () => {
175
+ const currentIndex = stepIds.indexOf(currentStep);
176
+ if (currentIndex < stepIds.length - 1) {
177
+ setTimeout(() => {
178
+ setCurrentStep(stepIds[currentIndex + 1]);
179
+ }, 100);
180
+ }
181
+ };
182
+ const handleBack = () => {
183
+ const currentIndex = stepIds.indexOf(currentStep);
184
+ if (currentIndex > 0) {
185
+ setTimeout(() => {
186
+ setCurrentStep(stepIds[currentIndex - 1]);
187
+ }, 100);
188
+ }
189
+ };
190
+ return {
191
+ currentStep,
192
+ dialogHeight,
193
+ visibleStepRef,
194
+ handleNext,
195
+ handleBack
196
+ };
197
+ };
198
+
199
+ // hooks/useClipboard.ts
200
+ import { useState as useState7 } from "react";
201
+ function useClipboard({ timeout = 2e3 } = {}) {
202
+ const [error, setError] = useState7(null);
203
+ const [copied, setCopied] = useState7(false);
204
+ const [copyTimeout, setCopyTimeout] = useState7(null);
205
+ const handleCopyResult = (value) => {
206
+ clearTimeout(copyTimeout);
207
+ setCopyTimeout(setTimeout(() => setCopied(false), timeout));
208
+ setCopied(value);
209
+ };
210
+ const copy = (valueToCopy) => {
211
+ if ("clipboard" in navigator) {
212
+ navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
213
+ } else {
214
+ setError(new Error("useClipboard: navigator.clipboard is not supported"));
215
+ }
216
+ };
217
+ const reset = () => {
218
+ setCopied(false);
219
+ setError(null);
220
+ clearTimeout(copyTimeout);
221
+ };
222
+ return { copy, reset, error, copied };
223
+ }
224
+
225
+ // hooks/useWindowSize.ts
226
+ import { useEffect as useEffect6, useState as useState8 } from "react";
227
+ var useWindowSize = () => {
228
+ const [windowSize, setWindowSize] = useState8({
229
+ width: void 0,
230
+ height: void 0
231
+ });
232
+ useEffect6(() => {
233
+ function handleResize() {
234
+ setWindowSize({
235
+ width: window.innerWidth,
236
+ height: window.innerHeight
237
+ });
238
+ }
239
+ window.addEventListener("resize", handleResize);
240
+ handleResize();
241
+ return () => window.removeEventListener("resize", handleResize);
242
+ }, []);
243
+ return windowSize;
244
+ };
245
+
246
+ // hooks/useFocusWithin.ts
247
+ import { useRef as useRef4, useState as useState9, useEffect as useEffect7 } from "react";
248
+ function containsRelatedTarget(event) {
249
+ if (event.currentTarget instanceof HTMLElement && event.relatedTarget instanceof HTMLElement) {
250
+ return event.currentTarget.contains(event.relatedTarget);
251
+ }
252
+ return false;
253
+ }
254
+ function useFocusWithin({
255
+ onBlur,
256
+ onFocus
257
+ } = {}) {
258
+ const ref = useRef4(null);
259
+ const [focused, _setFocused] = useState9(false);
260
+ const focusedRef = useRef4(false);
261
+ const setFocused = (value) => {
262
+ _setFocused(value);
263
+ focusedRef.current = value;
264
+ };
265
+ const handleFocusIn = (event) => {
266
+ if (!focusedRef.current) {
267
+ setFocused(true);
268
+ onFocus == null ? void 0 : onFocus(event);
269
+ }
270
+ };
271
+ const handleFocusOut = (event) => {
272
+ if (focusedRef.current && !containsRelatedTarget(event)) {
273
+ setFocused(false);
274
+ onBlur == null ? void 0 : onBlur(event);
275
+ }
276
+ };
277
+ useEffect7(() => {
278
+ if (ref.current) {
279
+ ref.current.addEventListener("focusin", handleFocusIn);
280
+ ref.current.addEventListener("focusout", handleFocusOut);
281
+ return () => {
282
+ var _a, _b;
283
+ (_a = ref.current) == null ? void 0 : _a.removeEventListener("focusin", handleFocusIn);
284
+ (_b = ref.current) == null ? void 0 : _b.removeEventListener("focusout", handleFocusOut);
285
+ };
286
+ }
287
+ return void 0;
288
+ }, [handleFocusIn, handleFocusOut]);
289
+ return { ref, focused };
290
+ }
291
+
292
+ // hooks/useMediaQuery.ts
293
+ import { useState as useState10, useEffect as useEffect8, useRef as useRef5 } from "react";
294
+ function attachMediaListener(query, callback) {
295
+ try {
296
+ query.addEventListener("change", callback);
297
+ return () => query.removeEventListener("change", callback);
298
+ } catch (e) {
299
+ query.addListener(callback);
300
+ return () => query.removeListener(callback);
301
+ }
302
+ }
303
+ function getInitialValue(query, initialValue) {
304
+ if (typeof initialValue === "boolean") {
305
+ return initialValue;
306
+ }
307
+ if (typeof window !== "undefined" && "matchMedia" in window) {
308
+ return window.matchMedia(query).matches;
309
+ }
310
+ return false;
311
+ }
312
+ function useMediaQuery(query, initialValue, { getInitialValueInEffect } = {
313
+ getInitialValueInEffect: true
314
+ }) {
315
+ const [matches, setMatches] = useState10(
316
+ getInitialValueInEffect ? initialValue : getInitialValue(query, initialValue)
317
+ );
318
+ const queryRef = useRef5();
319
+ useEffect8(() => {
320
+ if ("matchMedia" in window) {
321
+ queryRef.current = window.matchMedia(query);
322
+ setMatches(queryRef.current.matches);
323
+ return attachMediaListener(
324
+ queryRef.current,
325
+ (event) => setMatches(event.matches)
326
+ );
327
+ }
328
+ return void 0;
329
+ }, [query]);
330
+ return matches;
331
+ }
332
+
333
+ // hooks/useScrollPosition.ts
334
+ import { useState as useState11, useEffect as useEffect9 } from "react";
335
+
336
+ // hooks/useTable.ts
337
+ import { useState as useState12, useEffect as useEffect10 } from "react";
338
+
339
+ // hooks/useTabs.ts
340
+ import { useEffect as useEffect11, useState as useState13 } from "react";
341
+ function useTabs(initialTab = "") {
342
+ const [activeTab, setActiveTab] = useState13(initialTab);
343
+ useEffect11(() => {
344
+ const handleHashChange = () => {
345
+ const hash = window.location.hash.substring(1);
346
+ setActiveTab(hash || initialTab);
347
+ };
348
+ window.addEventListener("hashchange", handleHashChange);
349
+ handleHashChange();
350
+ return () => {
351
+ window.removeEventListener("hashchange", handleHashChange);
352
+ };
353
+ }, [initialTab]);
354
+ const handleTabChange = (index) => {
355
+ setActiveTab(index);
356
+ window.location.hash = index;
357
+ };
358
+ return {
359
+ activeTab,
360
+ handleTabChange
361
+ };
362
+ }
363
+
364
+ // hooks/useMeasureDirty.ts
365
+ import { useEffect as useEffect12, useRef as useRef7, useState as useState14 } from "react";
366
+ var useMeasureDirty = (ref) => {
367
+ const frame = useRef7(0);
368
+ const [rect, set] = useState14({
369
+ width: 0,
370
+ height: 0,
371
+ top: 0,
372
+ left: 0,
373
+ bottom: 0,
374
+ right: 0
375
+ });
376
+ const [observer] = useState14(
377
+ () => new ResizeObserver((entries) => {
378
+ const entry = entries[0];
379
+ if (entry) {
380
+ cancelAnimationFrame(frame.current);
381
+ frame.current = requestAnimationFrame(() => {
382
+ if (ref.current) {
383
+ set(entry.contentRect);
384
+ }
385
+ });
386
+ }
387
+ })
388
+ );
389
+ useEffect12(() => {
390
+ observer.disconnect();
391
+ if (ref.current) {
392
+ observer.observe(ref.current);
393
+ }
394
+ }, [ref]);
395
+ return rect;
396
+ };
397
+
398
+ export {
399
+ useIsomorphicEffect,
400
+ reducer,
401
+ toast,
402
+ useToast,
403
+ useDialogCarousel,
404
+ useMultiStepDialog,
405
+ useClipboard,
406
+ useWindowSize,
407
+ useFocusWithin,
408
+ useMediaQuery,
409
+ useTabs,
410
+ useMeasureDirty
411
+ };
@@ -1,4 +1,7 @@
1
1
  "use client";
2
+ import {
3
+ useMeasureDirty
4
+ } from "./chunk-R2SKHHDK.mjs";
2
5
  import {
3
6
  Button,
4
7
  Chip,
@@ -2866,27 +2869,39 @@ var FloatBox = ({
2866
2869
  open,
2867
2870
  side = "bottom",
2868
2871
  sideOffset = 40,
2872
+ align = "center",
2869
2873
  ...props
2870
2874
  }) => {
2871
- let widthStyles = {
2872
- trigger: "var(--radix-popover-trigger-width)",
2873
- default: "auto"
2874
- };
2875
- let sideOffsetStyles = {
2876
- bottom: { top: sideOffset },
2877
- top: { bottom: sideOffset },
2878
- right: { left: sideOffset },
2879
- left: { right: sideOffset }
2875
+ let stylesMap = {
2876
+ bottom: {
2877
+ start: { top: sideOffset, insetInlineStart: 0 },
2878
+ center: { top: sideOffset },
2879
+ end: { top: sideOffset, insetInlineEnd: 0 }
2880
+ },
2881
+ top: {
2882
+ start: { bottom: sideOffset, insetInlineStart: 0 },
2883
+ center: { bottom: sideOffset },
2884
+ end: { bottom: sideOffset, insetInlineEnd: 0 }
2885
+ },
2886
+ right: {
2887
+ start: { left: sideOffset, top: -5 },
2888
+ center: { left: sideOffset },
2889
+ end: { left: sideOffset, bottom: 0 }
2890
+ },
2891
+ left: {
2892
+ start: { right: sideOffset, top: 0 },
2893
+ center: { right: sideOffset },
2894
+ end: { right: sideOffset, bottom: 0 }
2895
+ }
2880
2896
  };
2881
2897
  return /* @__PURE__ */ React13.createElement(
2882
2898
  "div",
2883
2899
  {
2884
2900
  className: cn(
2885
2901
  "data-[floatbox-state=closed]:hawa-invisible data-[floatbox-state=open]:hawa-visible hawa-absolute dark:dark-shadow hawa-z-50 hawa-rounded hawa-border hawa-bg-popover hawa-text-popover-foreground hawa-shadow-md hawa-outline-none data-[floatbox-state=open]:hawa-animate-in data-[floatbox-state=closed]:hawa-animate-out data-[floatbox-state=closed]:hawa-fade-out-0 data-[floatbox-state=open]:hawa-fade-in-0 data-[floatbox-state=closed]:hawa-zoom-out-95 data-[floatbox-state=open]:hawa-zoom-in-95 data-[side=bottom]:hawa-slide-in-from-top-2 data-[side=left]:hawa-slide-in-from-right-2 data-[side=right]:hawa-slide-in-from-left-2 data-[side=top]:hawa-slide-in-from-bottom-2",
2886
- sideOffsetStyles[side],
2887
2902
  className
2888
2903
  ),
2889
- style: { ...sideOffsetStyles[side] },
2904
+ style: { ...stylesMap[side][align] },
2890
2905
  "data-side": side,
2891
2906
  "data-floatbox-state": open ? "open" : "closed"
2892
2907
  },
@@ -2984,10 +2999,12 @@ var TabsList = React14.forwardRef(({ className, ...props }, ref) => {
2984
2999
  });
2985
3000
  var TabsTrigger = React14.forwardRef(({ className, chipProps, ...props }, ref) => {
2986
3001
  const { orientation, variant } = React14.useContext(TabsContext);
3002
+ const tabTriggerRef = React14.useRef(null);
3003
+ const { width } = useMeasureDirty(tabTriggerRef);
2987
3004
  return /* @__PURE__ */ React14.createElement(
2988
3005
  TabsPrimitive.Trigger,
2989
3006
  {
2990
- ref,
3007
+ ref: tabTriggerRef,
2991
3008
  className: cn(
2992
3009
  tabsTriggerVariant({ variant, orientation }),
2993
3010
  "hawa-relative",
@@ -2997,7 +3014,16 @@ var TabsTrigger = React14.forwardRef(({ className, chipProps, ...props }, ref) =
2997
3014
  },
2998
3015
  props.children,
2999
3016
  chipProps && /* @__PURE__ */ React14.createElement(Chip, { ...chipProps }),
3000
- /* @__PURE__ */ React14.createElement(FloatBox, { open: props.showPopover }, props.popoverContent)
3017
+ /* @__PURE__ */ React14.createElement(
3018
+ FloatBox,
3019
+ {
3020
+ align: orientation === "vertical" ? "start" : "start",
3021
+ side: orientation === "vertical" ? "right" : "bottom",
3022
+ sideOffset: orientation === "vertical" ? width + 30 : 45,
3023
+ open: props.showPopover
3024
+ },
3025
+ props.popoverContent
3026
+ )
3001
3027
  );
3002
3028
  });
3003
3029
  var TabsContent = React14.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React14.createElement(
@@ -1,4 +1,11 @@
1
1
  "use client";
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined")
6
+ return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
2
9
 
3
10
  // hooks/useBreakpoint.ts
4
11
  import { useState, useEffect } from "react";
@@ -20,5 +27,6 @@ var useBreakpoint = () => {
20
27
  };
21
28
 
22
29
  export {
30
+ __require,
23
31
  useBreakpoint
24
32
  };