@yimingliao/cms 0.0.84 → 0.0.86

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.
@@ -1,4 +1,4 @@
1
- import { R as Result, S as SuccessResult, d as ErrorResult, g as AdminFull, D as DeviceInfo } from '../types-BGsFazJr.js';
1
+ import { z as Translation, R as Result, S as SuccessResult, d as ErrorResult, g as AdminFull, D as DeviceInfo } from '../types-BGsFazJr.js';
2
2
  import { Logger } from 'logry';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { QueryClient, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
@@ -28,6 +28,17 @@ interface UIStates {
28
28
  isDisabled?: boolean;
29
29
  isError?: boolean;
30
30
  }
31
+ interface FormContext<T> {
32
+ formData?: T;
33
+ setFormData?: React$1.Dispatch<React$1.SetStateAction<T>>;
34
+ }
35
+ interface FieldContext {
36
+ fieldName?: string;
37
+ translations?: Translation[];
38
+ errors?: string[];
39
+ }
40
+ interface FormFieldController<T = Record<string, unknown>> extends UIStates, FormContext<T>, FieldContext {
41
+ }
31
42
 
32
43
  interface FetchContext {
33
44
  input: string;
@@ -342,23 +353,49 @@ declare const buttonVariants: (props?: ({
342
353
  variant?: "link" | "default" | "success" | "destructive" | "outline" | "secondary" | "ghost" | "warning" | null | undefined;
343
354
  size?: "lg" | "sm" | "default" | "icon" | "icon-sm" | "icon-lg" | "xs" | null | undefined;
344
355
  } & class_variance_authority_types.ClassProp) | undefined) => string;
345
- type ShadcnButtonProps = React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
356
+ type ButtonProps$1 = React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
346
357
  asChild?: boolean;
347
358
  };
359
+ declare function Button$1({ className, variant, size, asChild, ...props }: ButtonProps$1): react_jsx_runtime.JSX.Element;
348
360
 
349
- interface ButtonProps extends ShadcnButtonProps, UIStates {
361
+ declare function Card({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
362
+ declare function CardHeader({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
363
+ declare function CardTitle({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
364
+ declare function CardDescription({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
365
+ declare function CardAction({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
366
+ declare function CardContent({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
367
+ declare function CardFooter({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
368
+
369
+ declare function InputGroup({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
370
+ declare const inputGroupAddonVariants: (props?: ({
371
+ align?: "inline-start" | "inline-end" | "block-start" | "block-end" | null | undefined;
372
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
373
+ declare function InputGroupAddon({ className, align, ...props }: React$1.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>): react_jsx_runtime.JSX.Element;
374
+ declare const inputGroupButtonVariants: (props?: ({
375
+ size?: "sm" | "icon-sm" | "xs" | "icon-xs" | null | undefined;
376
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
377
+ declare function InputGroupButton({ className, type, variant, size, ...props }: Omit<React$1.ComponentProps<typeof Button$1>, "size"> & VariantProps<typeof inputGroupButtonVariants>): react_jsx_runtime.JSX.Element;
378
+ declare function InputGroupText({ className, ...props }: React$1.ComponentProps<"span">): react_jsx_runtime.JSX.Element;
379
+ declare function InputGroupInput({ className, ...props }: React$1.ComponentProps<"input">): react_jsx_runtime.JSX.Element;
380
+ declare function InputGroupTextarea({ className, ...props }: React$1.ComponentProps<"textarea">): react_jsx_runtime.JSX.Element;
381
+
382
+ declare function Spinner({ className, ...props }: ComponentProps<"svg">): react_jsx_runtime.JSX.Element;
383
+
384
+ declare function Textarea({ className, ...props }: React$1.ComponentProps<"textarea">): react_jsx_runtime.JSX.Element;
385
+
386
+ interface ButtonProps extends ButtonProps$1, UIStates {
350
387
  icon?: LucideIcon;
351
388
  href?: string;
352
389
  openNewTab?: boolean;
353
390
  }
354
391
  declare function Button({ icon, href, openNewTab, isDisabled, isLoading, children, ...props }: ButtonProps): react_jsx_runtime.JSX.Element;
355
392
 
356
- declare function AuthForm({ title, children, className, ...props }: ComponentProps<"form"> & {
357
- title: string;
358
- }): react_jsx_runtime.JSX.Element;
393
+ interface InputProps<T = Record<string, unknown>> extends ComponentProps<"input">, FormFieldController<T> {
394
+ }
395
+ declare function Input<T>({ fieldName, setFormData, isLoading, isDisabled, isError, children, ...props }: InputProps<T>): react_jsx_runtime.JSX.Element;
359
396
 
360
397
  declare const cn: (...inputs: ClassValue[]) => string;
361
398
 
362
399
  declare function useDeviceInfo(): DeviceInfo | null;
363
400
 
364
- export { AdminProvider, AuthForm, Button, type ButtonProps, Form, type ShowToastOption, cn, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin, useDeviceInfo };
401
+ export { AdminProvider, Button, type ButtonProps, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Form, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, type InputProps, type ShowToastOption, Spinner, Textarea, cn, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin, useDeviceInfo };
@@ -2,7 +2,7 @@ import { ensureArray } from '../chunk-OAENV763.js';
2
2
  import { toast } from 'sonner';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
  import { useMutation, useQuery } from '@tanstack/react-query';
5
- import * as React2 from 'react';
5
+ import * as React6 from 'react';
6
6
  import { createContext, useState, useContext, useEffect } from 'react';
7
7
  import { clsx } from 'clsx';
8
8
  import { twMerge } from 'tailwind-merge';
@@ -308,7 +308,7 @@ var buttonVariants = cva(
308
308
  }
309
309
  }
310
310
  );
311
- function ShadCnButton({
311
+ function Button({
312
312
  className,
313
313
  variant,
314
314
  size,
@@ -325,51 +325,6 @@ function ShadCnButton({
325
325
  }
326
326
  );
327
327
  }
328
- function Spinner({ className, ...props }) {
329
- return /* @__PURE__ */ jsx(
330
- Loader2Icon,
331
- {
332
- role: "status",
333
- "aria-label": "Loading",
334
- className: cn("size-4 animate-spin", className),
335
- ...props
336
- }
337
- );
338
- }
339
- function Button({
340
- icon,
341
- href,
342
- openNewTab = false,
343
- // processing states
344
- isDisabled = false,
345
- isLoading = false,
346
- // base
347
- children,
348
- ...props
349
- }) {
350
- const router = useRouter();
351
- const handleClick = () => {
352
- if (!href) return;
353
- if (openNewTab) {
354
- window.open(href, "_blank");
355
- } else {
356
- router.push(href);
357
- }
358
- };
359
- return /* @__PURE__ */ jsx(
360
- ShadCnButton,
361
- {
362
- type: props.type ?? "button",
363
- disabled: isDisabled || isLoading,
364
- onClick: props.onClick ?? handleClick,
365
- ...props,
366
- children: isLoading ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
367
- icon && React2.createElement(icon),
368
- children
369
- ] })
370
- }
371
- );
372
- }
373
328
  function Card({ className, ...props }) {
374
329
  return /* @__PURE__ */ jsx(
375
330
  "div",
@@ -406,6 +361,29 @@ function CardTitle({ className, ...props }) {
406
361
  }
407
362
  );
408
363
  }
364
+ function CardDescription({ className, ...props }) {
365
+ return /* @__PURE__ */ jsx(
366
+ "div",
367
+ {
368
+ "data-slot": "card-description",
369
+ className: cn("text-muted-foreground text-sm", className),
370
+ ...props
371
+ }
372
+ );
373
+ }
374
+ function CardAction({ className, ...props }) {
375
+ return /* @__PURE__ */ jsx(
376
+ "div",
377
+ {
378
+ "data-slot": "card-action",
379
+ className: cn(
380
+ "col-start-2 row-span-2 row-start-1 self-start justify-self-end",
381
+ className
382
+ ),
383
+ ...props
384
+ }
385
+ );
386
+ }
409
387
  function CardContent({ className, ...props }) {
410
388
  return /* @__PURE__ */ jsx(
411
389
  "div",
@@ -416,16 +394,259 @@ function CardContent({ className, ...props }) {
416
394
  }
417
395
  );
418
396
  }
419
- function AuthForm({
420
- title,
421
- children,
397
+ function CardFooter({ className, ...props }) {
398
+ return /* @__PURE__ */ jsx(
399
+ "div",
400
+ {
401
+ "data-slot": "card-footer",
402
+ className: cn("flex items-center px-6 [.border-t]:pt-6", className),
403
+ ...props
404
+ }
405
+ );
406
+ }
407
+ function Input({ className, type, ...props }) {
408
+ return /* @__PURE__ */ jsx(
409
+ "input",
410
+ {
411
+ type,
412
+ "data-slot": "input",
413
+ className: cn(
414
+ "file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
415
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
416
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
417
+ className
418
+ ),
419
+ ...props
420
+ }
421
+ );
422
+ }
423
+ function Textarea({ className, ...props }) {
424
+ return /* @__PURE__ */ jsx(
425
+ "textarea",
426
+ {
427
+ "data-slot": "textarea",
428
+ className: cn(
429
+ // "min-h-16",
430
+ // "field-sizing-content",
431
+ "border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
432
+ className
433
+ ),
434
+ ...props
435
+ }
436
+ );
437
+ }
438
+ function InputGroup({ className, ...props }) {
439
+ return /* @__PURE__ */ jsx(
440
+ "div",
441
+ {
442
+ "data-slot": "input-group",
443
+ role: "group",
444
+ className: cn(
445
+ "group/input-group border-input dark:bg-input/30 relative flex w-full items-center rounded-md border shadow-xs transition-[color,box-shadow] outline-none",
446
+ "h-9 min-w-0 has-[>textarea]:h-auto",
447
+ // Variants based on alignment.
448
+ "has-[>[data-align=inline-start]]:[&>input]:pl-2",
449
+ "has-[>[data-align=inline-end]]:[&>input]:pr-2",
450
+ "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3",
451
+ "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3",
452
+ // Focus state.
453
+ "has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot=input-group-control]:focus-visible]:ring-[3px]",
454
+ // Error state.
455
+ "has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
456
+ className
457
+ ),
458
+ ...props
459
+ }
460
+ );
461
+ }
462
+ var inputGroupAddonVariants = cva(
463
+ "text-muted-foreground flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium select-none [&>svg:not([class*='size-'])]:size-4 [&>kbd]:rounded-[calc(var(--radius)-5px)] group-data-[disabled=true]/input-group:opacity-50",
464
+ {
465
+ variants: {
466
+ align: {
467
+ "inline-start": "order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
468
+ "inline-end": "order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
469
+ "block-start": "order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3 group-has-[>input]/input-group:pt-2.5",
470
+ "block-end": "order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3 group-has-[>input]/input-group:pb-2.5"
471
+ }
472
+ },
473
+ defaultVariants: {
474
+ align: "inline-start"
475
+ }
476
+ }
477
+ );
478
+ function InputGroupAddon({
422
479
  className,
480
+ align = "inline-start",
423
481
  ...props
424
482
  }) {
425
- return /* @__PURE__ */ jsx(Form, { className: cn("mx-auto mt-14 w-96", className), ...props, children: /* @__PURE__ */ jsxs(Card, { children: [
426
- /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { className: "mx-auto", children: title }) }),
427
- /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("div", { className: "relative flex flex-col gap-6", children }) })
428
- ] }) });
483
+ return /* @__PURE__ */ jsx(
484
+ "div",
485
+ {
486
+ role: "group",
487
+ "data-slot": "input-group-addon",
488
+ "data-align": align,
489
+ className: cn(inputGroupAddonVariants({ align }), className),
490
+ onClick: (e) => {
491
+ if (e.target.closest("button")) {
492
+ return;
493
+ }
494
+ e.currentTarget.parentElement?.querySelector("input")?.focus();
495
+ },
496
+ ...props
497
+ }
498
+ );
499
+ }
500
+ var inputGroupButtonVariants = cva(
501
+ "text-sm shadow-none flex gap-2 items-center",
502
+ {
503
+ variants: {
504
+ size: {
505
+ xs: "h-6 gap-1 px-2 rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-3.5 has-[>svg]:px-2",
506
+ sm: "h-8 px-2.5 gap-1.5 rounded-md has-[>svg]:px-2.5",
507
+ "icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
508
+ "icon-sm": "size-8 p-0 has-[>svg]:p-0"
509
+ }
510
+ },
511
+ defaultVariants: {
512
+ size: "xs"
513
+ }
514
+ }
515
+ );
516
+ function InputGroupButton({
517
+ className,
518
+ type = "button",
519
+ variant = "ghost",
520
+ size = "xs",
521
+ ...props
522
+ }) {
523
+ return /* @__PURE__ */ jsx(
524
+ Button,
525
+ {
526
+ type,
527
+ "data-size": size,
528
+ variant,
529
+ className: cn(inputGroupButtonVariants({ size }), className),
530
+ ...props
531
+ }
532
+ );
533
+ }
534
+ function InputGroupText({ className, ...props }) {
535
+ return /* @__PURE__ */ jsx(
536
+ "span",
537
+ {
538
+ className: cn(
539
+ "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
540
+ className
541
+ ),
542
+ ...props
543
+ }
544
+ );
545
+ }
546
+ function InputGroupInput({
547
+ className,
548
+ ...props
549
+ }) {
550
+ return /* @__PURE__ */ jsx(
551
+ Input,
552
+ {
553
+ "data-slot": "input-group-control",
554
+ className: cn(
555
+ "flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
556
+ className
557
+ ),
558
+ ...props
559
+ }
560
+ );
561
+ }
562
+ function InputGroupTextarea({
563
+ className,
564
+ ...props
565
+ }) {
566
+ return /* @__PURE__ */ jsx(
567
+ Textarea,
568
+ {
569
+ "data-slot": "input-group-control",
570
+ className: cn(
571
+ "flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
572
+ className
573
+ ),
574
+ ...props
575
+ }
576
+ );
577
+ }
578
+ function Spinner({ className, ...props }) {
579
+ return /* @__PURE__ */ jsx(
580
+ Loader2Icon,
581
+ {
582
+ role: "status",
583
+ "aria-label": "Loading",
584
+ className: cn("size-4 animate-spin", className),
585
+ ...props
586
+ }
587
+ );
588
+ }
589
+ function Button2({
590
+ icon,
591
+ href,
592
+ openNewTab = false,
593
+ // ui states
594
+ isDisabled = false,
595
+ isLoading = false,
596
+ // base
597
+ children,
598
+ ...props
599
+ }) {
600
+ const router = useRouter();
601
+ const handleClick = () => {
602
+ if (!href) return;
603
+ if (openNewTab) {
604
+ window.open(href, "_blank");
605
+ } else {
606
+ router.push(href);
607
+ }
608
+ };
609
+ return /* @__PURE__ */ jsx(
610
+ Button,
611
+ {
612
+ type: props.type ?? "button",
613
+ disabled: isDisabled || isLoading,
614
+ onClick: props.onClick ?? handleClick,
615
+ ...props,
616
+ children: isLoading ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
617
+ icon && React6.createElement(icon),
618
+ children
619
+ ] })
620
+ }
621
+ );
622
+ }
623
+ function Input2({
624
+ // form context
625
+ fieldName,
626
+ setFormData,
627
+ // ui states
628
+ isLoading = false,
629
+ isDisabled = false,
630
+ isError = false,
631
+ // base
632
+ children,
633
+ ...props
634
+ }) {
635
+ return /* @__PURE__ */ jsxs(InputGroup, { "data-disabled": isDisabled || isLoading, children: [
636
+ isLoading ? /* @__PURE__ */ jsx(InputGroupAddon, { children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsx(
637
+ InputGroupInput,
638
+ {
639
+ disabled: isDisabled || isLoading,
640
+ "aria-invalid": isError,
641
+ onChange: (e) => {
642
+ if (!setFormData || !fieldName) return;
643
+ setFormData((p) => ({ ...p, [fieldName]: e.target.value }));
644
+ },
645
+ ...props
646
+ }
647
+ ),
648
+ children
649
+ ] });
429
650
  }
430
651
 
431
- export { AdminProvider, AuthForm, Button, Form, cn, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin, useDeviceInfo };
652
+ export { AdminProvider, Button2 as Button, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Form, Input2 as Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, Spinner, Textarea, cn, createAdminInitializer, createRequestInterceptor, createResponseInterceptor, createSmartFetch, createUseCommand, createUseQuery, handleToast, useAdmin, useDeviceInfo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yimingliao/cms",
3
- "version": "0.0.84",
3
+ "version": "0.0.86",
4
4
  "author": "Yiming Liao",
5
5
  "license": "MIT",
6
6
  "type": "module",