@doscientos/ui 0.1.12 → 0.1.13

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/index.cjs CHANGED
@@ -254,12 +254,12 @@ function useAutosave({
254
254
  }, []);
255
255
  (0, import_react.useEffect)(() => {
256
256
  if (!enabled) return;
257
- const snapshot2 = serializeRef.current(data);
257
+ const snapshot = serializeRef.current(data);
258
258
  if (lastSaved.current === null) {
259
- lastSaved.current = snapshot2;
259
+ lastSaved.current = snapshot;
260
260
  return;
261
261
  }
262
- if (snapshot2 === lastSaved.current) return;
262
+ if (snapshot === lastSaved.current) return;
263
263
  const timeout = window.setTimeout(() => void save(data), debounceMs);
264
264
  return () => window.clearTimeout(timeout);
265
265
  }, [data, debounceMs, enabled, save]);
@@ -2744,46 +2744,40 @@ function TabsContent({ className, ...props }) {
2744
2744
 
2745
2745
  // src/ui/toast/toast.tsx
2746
2746
  var import_react12 = require("react");
2747
- var import_lucide_react14 = require("lucide-react");
2747
+ var import_sileo = require("sileo");
2748
2748
  var import_jsx_runtime45 = require("react/jsx-runtime");
2749
- var records = [];
2750
- var listeners = /* @__PURE__ */ new Set();
2751
- var snapshot = () => records;
2752
- var emit = () => listeners.forEach((listener) => listener());
2753
- var subscribe = (listener) => {
2754
- listeners.add(listener);
2755
- return () => listeners.delete(listener);
2756
- };
2757
- var remove = (id) => {
2758
- records = records.filter((record) => record.id !== id);
2759
- emit();
2760
- };
2761
- function create(options) {
2762
- const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
2763
- records = [...records, { ...options, id, state: "open", variant: options.variant ?? "default", duration: options.duration ?? 5e3, position: options.position ?? "bottom-right" }];
2764
- emit();
2765
- return id;
2766
- }
2767
- function dismiss(id) {
2768
- if (!records.some((record) => record.id === id && record.state === "open")) return;
2769
- records = records.map((record) => record.id === id ? { ...record, state: "closing" } : record);
2770
- emit();
2771
- window.setTimeout(() => remove(id), 180);
2749
+ function toSileoOptions({ title, description, duration, position, action }) {
2750
+ return {
2751
+ title,
2752
+ description,
2753
+ duration: duration === 0 ? null : duration,
2754
+ position,
2755
+ button: action ? { title: action.label, onClick: action.onPress } : void 0
2756
+ };
2772
2757
  }
2773
- function update(id, patch) {
2774
- records = records.map((record) => record.id === id ? { ...record, ...patch, state: "open" } : record);
2775
- emit();
2758
+ function create(options) {
2759
+ const sileoOptions = toSileoOptions(options);
2760
+ if (options.action) return import_sileo.sileo.action(sileoOptions);
2761
+ if (options.variant === "success") return import_sileo.sileo.success(sileoOptions);
2762
+ if (options.variant === "error") return import_sileo.sileo.error(sileoOptions);
2763
+ if (options.variant === "warning") return import_sileo.sileo.warning(sileoOptions);
2764
+ if (options.variant === "info") return import_sileo.sileo.info(sileoOptions);
2765
+ return import_sileo.sileo.show(sileoOptions);
2776
2766
  }
2777
2767
  var toast = Object.assign((options) => create(options), {
2778
2768
  success: (title, options) => create({ ...options, title, variant: "success" }),
2779
2769
  error: (title, options) => create({ ...options, title, variant: "error" }),
2780
2770
  warning: (title, options) => create({ ...options, title, variant: "warning" }),
2781
2771
  info: (title, options) => create({ ...options, title, variant: "info" }),
2782
- dismiss,
2772
+ dismiss: (id) => import_sileo.sileo.dismiss(id),
2783
2773
  promise: (promise, options) => {
2784
- const id = create({ title: options.loading, description: options.description, variant: "default", duration: 0, position: options.position });
2785
- promise.then((value) => update(id, { title: typeof options.success === "function" ? options.success(value) : options.success, variant: "success", duration: 4e3 })).catch((error) => update(id, { title: typeof options.error === "function" ? options.error(error) : options.error, variant: "error", duration: 6e3 }));
2786
- return promise;
2774
+ const shared = { description: options.description, position: options.position };
2775
+ return import_sileo.sileo.promise(promise, {
2776
+ loading: { ...shared, title: options.loading },
2777
+ success: (value) => ({ ...shared, title: typeof options.success === "function" ? options.success(value) : options.success }),
2778
+ error: (error) => ({ ...shared, title: typeof options.error === "function" ? options.error(error) : options.error }),
2779
+ position: options.position
2780
+ });
2787
2781
  }
2788
2782
  });
2789
2783
  function useToast() {
@@ -2795,38 +2789,24 @@ function ToastProvider({ children }) {
2795
2789
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Toaster, {})
2796
2790
  ] });
2797
2791
  }
2798
- var positionClasses = {
2799
- "top-left": "top-4 left-4 items-start",
2800
- "top-center": "top-4 left-1/2 -translate-x-1/2 items-center",
2801
- "top-right": "top-4 right-4 items-end",
2802
- "bottom-left": "bottom-4 left-4 items-start",
2803
- "bottom-center": "bottom-4 left-1/2 -translate-x-1/2 items-center",
2804
- "bottom-right": "bottom-4 right-4 items-end"
2805
- };
2806
- function Toaster({ position = "bottom-right" }) {
2807
- return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_jsx_runtime45.Fragment, { children: Object.keys(positionClasses).map((item) => /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(ToastViewport, { position: item, visiblePosition: position }, item)) });
2792
+ function Toaster({ position }) {
2793
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_sileo.Toaster, { position });
2808
2794
  }
2809
2795
  function ToastViewport({ position, visiblePosition, className }) {
2810
- const toasts = (0, import_react12.useSyncExternalStore)(subscribe, snapshot, snapshot).filter((item) => item.position === position);
2811
- if (visiblePosition && position !== visiblePosition && toasts.length === 0) return null;
2812
- return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { "aria-label": `Notificaciones ${position}`, className: cn("pointer-events-none fixed z-50 flex w-[min(24rem,calc(100vw-2rem))] flex-col gap-2", positionClasses[position], className), children: toasts.map((item) => /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Toast, { ...item, onDismiss: () => dismiss(item.id) }, item.id)) });
2796
+ void className;
2797
+ if (visiblePosition && visiblePosition !== position) return null;
2798
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Toaster, { position });
2813
2799
  }
2814
- function Toast({ id, title, description, variant = "default", action, state = "open", duration = 0, onDismiss }) {
2800
+ function Toast({ id, title, description, variant = "default", action, state = "open", duration = 0, position, onDismiss }) {
2815
2801
  (0, import_react12.useEffect)(() => {
2816
- if (state !== "open" || duration <= 0) return;
2817
- const timeout = window.setTimeout(() => dismiss(id), duration);
2818
- return () => window.clearTimeout(timeout);
2819
- }, [duration, id, state]);
2820
- const Icon = variant === "success" ? import_lucide_react14.CheckCircle : variant === "error" ? import_lucide_react14.XCircle : variant === "warning" ? import_lucide_react14.CircleAlert : variant === "info" ? import_lucide_react14.Info : import_lucide_react14.Info;
2821
- return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { role: variant === "error" ? "alert" : "status", "data-state": state, className: cn("pointer-events-auto w-full overflow-hidden rounded-xl border border-border/80 bg-background/95 p-3.5 text-foreground shadow-xl shadow-black/10 backdrop-blur-md animate-ui-toast-in", "data-[state=closing]:animate-ui-toast-out motion-reduce:animate-none", variant === "success" && "border-success/30", variant === "error" && "border-destructive/30", variant === "warning" && "border-warning/40"), children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex items-start gap-3", children: [
2822
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Icon, { "aria-hidden": "true", className: cn("mt-0.5 size-5 shrink-0", variant === "success" && "text-success", variant === "error" && "text-destructive", variant === "warning" && "text-warning", variant === "info" && "text-primary") }),
2823
- /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "min-w-0 flex-1", children: [
2824
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("p", { className: "animate-ui-toast-title text-sm font-semibold", children: title }),
2825
- description && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("p", { className: "mt-1 max-h-20 animate-ui-toast-description overflow-hidden text-sm leading-5 text-muted-foreground data-[state=closing]:max-h-0", "data-state": state, children: description }),
2826
- action && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Button, { size: "sm", variant: "link", onPress: action.onPress, className: "mt-1 h-auto px-0", children: action.label })
2827
- ] }),
2828
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Button, { "aria-label": "Cerrar notificaci\xF3n", onPress: onDismiss, size: "icon", variant: "ghost", className: "-mr-2 -mt-2 size-7", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(import_lucide_react14.X, {}) })
2829
- ] }) });
2802
+ if (state !== "open") return;
2803
+ const toastId = create({ title, description, variant, action, duration, position });
2804
+ return () => {
2805
+ import_sileo.sileo.dismiss(toastId);
2806
+ onDismiss?.();
2807
+ };
2808
+ }, [action, description, duration, id, onDismiss, position, state, title, variant]);
2809
+ return null;
2830
2810
  }
2831
2811
 
2832
2812
  // src/ui/toolbar/toolbar.tsx