@sonamu-kit/react-components 0.4.7 → 0.4.8

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.
Files changed (61) hide show
  1. package/dist/components/ui/calendar.js +12 -6
  2. package/dist/components/ui/calendar.js.map +1 -1
  3. package/dist/components/ui/carousel.js +12 -16
  4. package/dist/components/ui/carousel.js.map +1 -1
  5. package/dist/components/ui/common-modal.d.ts +6 -6
  6. package/dist/components/ui/common-modal.js.map +1 -1
  7. package/dist/components/ui/file-input.js +131 -130
  8. package/dist/components/ui/file-input.js.map +1 -1
  9. package/dist/components/ui/input.js +21 -20
  10. package/dist/components/ui/input.js.map +1 -1
  11. package/dist/components/ui/month-picker-multiple.js +31 -19
  12. package/dist/components/ui/month-picker-multiple.js.map +1 -1
  13. package/dist/components/ui/pagination.js +18 -17
  14. package/dist/components/ui/pagination.js.map +1 -1
  15. package/dist/components/ui/select/enum-select.js +4 -2
  16. package/dist/components/ui/select/enum-select.js.map +1 -1
  17. package/dist/components/ui/select/id-async-select.d.ts +32 -14
  18. package/dist/components/ui/select/id-async-select.js +185 -144
  19. package/dist/components/ui/select/id-async-select.js.map +1 -1
  20. package/dist/components/ui/select/select.js +199 -158
  21. package/dist/components/ui/select/select.js.map +1 -1
  22. package/dist/components/ui/sidebar.d.ts +2 -1
  23. package/dist/components/ui/sidebar.js +54 -45
  24. package/dist/components/ui/sidebar.js.map +1 -1
  25. package/dist/components/ui/sonamu-filter/constants.d.ts +27 -3
  26. package/dist/components/ui/sonamu-filter/constants.js.map +1 -1
  27. package/dist/components/ui/sonamu-filter/rule-row-input.js +18 -15
  28. package/dist/components/ui/sonamu-filter/rule-row-input.js.map +1 -1
  29. package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js +34 -37
  30. package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js.map +1 -1
  31. package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js +17 -12
  32. package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js.map +1 -1
  33. package/dist/components/ui/sonamu-filter/types.d.ts +14 -9
  34. package/dist/components/ui/sonamu-filter/utils.d.ts +9 -7
  35. package/dist/components/ui/sonamu-filter/utils.js +39 -20
  36. package/dist/components/ui/sonamu-filter/utils.js.map +1 -1
  37. package/dist/components/ui/sonamu-filter/value-input.js +65 -50
  38. package/dist/components/ui/sonamu-filter/value-input.js.map +1 -1
  39. package/dist/contexts/sonamu-context.js +34 -10
  40. package/dist/contexts/sonamu-context.js.map +1 -1
  41. package/dist/demo/components/FormDebugPanel.d.ts +1 -1
  42. package/dist/hooks/use-toast.d.ts +1 -1
  43. package/dist/hooks/use-toast.js.map +1 -1
  44. package/dist/lib/base-helpers.d.ts +1 -1
  45. package/dist/lib/base-helpers.js +10 -10
  46. package/dist/lib/base-helpers.js.map +1 -1
  47. package/dist/lib/caster.d.ts +3 -2
  48. package/dist/lib/caster.js +37 -19
  49. package/dist/lib/caster.js.map +1 -1
  50. package/dist/lib/form-helpers.js +38 -35
  51. package/dist/lib/form-helpers.js.map +1 -1
  52. package/dist/lib/list-helpers.d.ts +2 -2
  53. package/dist/lib/list-helpers.js +33 -36
  54. package/dist/lib/list-helpers.js.map +1 -1
  55. package/dist/lib/use-mobile.js +5 -7
  56. package/dist/lib/use-mobile.js.map +1 -1
  57. package/dist/lib/utils.d.ts +0 -14
  58. package/dist/lib/utils.js +24 -14
  59. package/dist/lib/utils.js.map +1 -1
  60. package/dist/styles/globals.css +38 -106
  61. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"file-input.js","names":[],"sources":["../../../src/components/ui/file-input.tsx"],"sourcesContent":["import type React from \"react\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { FileIcon as ReactFileIcon, defaultStyles } from \"react-file-icon\";\nimport ImageIcon from \"~icons/lucide/image\";\nimport Loader2Icon from \"~icons/lucide/loader2\";\nimport UploadIcon from \"~icons/lucide/upload\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type SonamuFile, type UploadParams } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\nimport { cn, useObjectUrls } from \"@/lib/utils\";\n\nimport { Button } from \"./button\";\n\nexport type PreviewSize = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nfunction getFileExtension(filename: string): string {\n const parts = filename.split(\".\");\n if (parts.length < 2) return \"\";\n return parts[parts.length - 1].toLowerCase();\n}\n\nconst fileIconSizes: Record<PreviewSize, number> = {\n sm: 14,\n md: 18,\n lg: 22,\n xl: 26,\n};\n\nfunction FileTypeIcon({ filename, size = \"md\" }: { filename: string; size?: PreviewSize }) {\n const ext = getFileExtension(filename);\n const styleProps =\n ext && ext in defaultStyles ? defaultStyles[ext as keyof typeof defaultStyles] : {};\n\n return (\n <div className=\"shrink-0 self-center\" style={{ width: fileIconSizes[size], marginTop: -2 }}>\n <ReactFileIcon extension={ext || undefined} {...styleProps} />\n </div>\n );\n}\n\n// 이미지용: 정사각형\nconst imageSizeClasses: Record<PreviewSize, string> = {\n sm: \"w-20 h-20\",\n md: \"w-32 h-32\",\n lg: \"w-40 h-40\",\n xl: \"w-48 h-48\",\n};\n\n// 파일용: 가로로 긴 직사각형\nconst fileSizeClasses: Record<PreviewSize, string> = {\n sm: \"w-48 h-12\",\n md: \"w-80 h-16\",\n lg: \"w-96 h-20\",\n xl: \"w-[28rem] h-24\",\n};\n\ntype BaseProps = {\n uploadMode: \"eager\" | \"lazy\";\n viewMode: \"image\" | \"file\";\n placeholder?: string;\n accept?: string;\n disabled?: boolean;\n className?: string;\n previewSize?: PreviewSize;\n uploadParams?: UploadParams;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n};\n\ntype SingleModeProps = BaseProps & {\n multiple?: false;\n value: SonamuFile | File | null;\n onValueChange?: (value: SonamuFile | File | null) => void;\n};\n\ntype MultipleModeProps = BaseProps & {\n multiple: true;\n value: (SonamuFile | File)[] | null;\n onValueChange?: (value: (SonamuFile | File)[]) => void;\n maxFiles?: number;\n};\n\nexport type FileInputProps = SingleModeProps | MultipleModeProps;\n\nexport function FileInput(props: FileInputProps) {\n const {\n placeholder,\n disabled = false,\n className,\n previewSize = \"md\",\n uploadMode,\n viewMode,\n uploadParams,\n onBlur,\n } = props;\n\n const { uploader, SD } = useSonamuBaseContext();\n\n const isMultiple = props.multiple ?? false;\n const isImageView = viewMode === \"image\";\n\n // viewMode에 따라 accept 자동 설정\n const accept = props.accept ?? (isImageView ? \"image/*\" : \"*/*\");\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [isUploading, setIsUploading] = useState(false);\n const [dragOver, setDragOver] = useState(false);\n\n // 기본 placeholder 설정\n const defaultPlaceholder =\n placeholder ??\n `${isImageView ? SD(\"rc.fileInput.imagePlaceholder\") : SD(\"rc.fileInput.filePlaceholder\")} URL${isMultiple ? \"S\" : \"\"}`;\n\n // 입력 정규화: 내부적으로 배열로 통일\n const values = (() => {\n if (!isMultiple) {\n const singleValue = (props as SingleModeProps).value;\n return singleValue ? [singleValue] : [];\n }\n\n const multiValue = (props as MultipleModeProps).value || [];\n\n return multiValue;\n })();\n\n // File 객체만 추출\n const fileObjects = values.filter((v): v is File => v instanceof File);\n\n // File 객체는 useObjectUrls로 안전하게 blob URL 생성 (자동 메모리 해제)\n const blobUrls = useObjectUrls(fileObjects);\n\n // 최종 display 데이터: 원래 순서를 유지하면서 File은 blob URL로, SonamuFile은 그대로\n const displayItems = values.map((v) => {\n if (v instanceof File) {\n const index = fileObjects.indexOf(v);\n return {\n url: blobUrls[index],\n name: v.name,\n isPending: true,\n };\n }\n // SonamuFile\n return {\n url: v.url,\n name: v.name,\n isPending: false,\n };\n });\n\n const maxFiles = isMultiple ? ((props as MultipleModeProps).maxFiles ?? 10) : 1;\n const totalCount = values.length;\n const canAddMore = totalCount < maxFiles;\n\n const handleFilesChange = useCallback(\n async (files: File[]) => {\n if (files.length === 0 || disabled) return;\n\n // maxFiles 체크\n const remainingSlots = maxFiles - totalCount;\n if (remainingSlots <= 0) {\n alert(\n (SD(\"rc.fileInput.maxFilesExceeded\") as unknown as (maxFiles: number) => string)(\n maxFiles,\n ),\n );\n return;\n }\n\n const filesToAdd = files.slice(0, remainingSlots);\n\n // Eager 모드: 즉시 업로드\n if (uploadMode === \"eager\") {\n setIsUploading(true);\n try {\n const uploadedFiles = await uploader(filesToAdd, uploadParams);\n\n if (isMultiple) {\n // Multiple 파일 업로드\n const finalValues = [...values, ...uploadedFiles];\n (props.onValueChange as ((v: (SonamuFile | File)[]) => void) | undefined)?.(\n finalValues,\n );\n } else {\n // Single 파일 업로드\n (props.onValueChange as ((v: SonamuFile | File) => void) | undefined)?.(\n uploadedFiles[0],\n );\n }\n } catch (error) {\n console.error(\"Upload failed:\", error);\n alert(SD(\"rc.fileInput.uploadFailed\"));\n } finally {\n setIsUploading(false);\n }\n } else {\n // Lazy 모드: File 객체 그대로 전달\n if (isMultiple) {\n const finalValues = [...values, ...filesToAdd];\n (props.onValueChange as ((v: (SonamuFile | File)[]) => void) | undefined)?.(finalValues);\n } else {\n (props.onValueChange as ((v: SonamuFile | File) => void) | undefined)?.(filesToAdd[0]);\n }\n }\n },\n [disabled, totalCount, maxFiles, isMultiple, uploadMode, uploadParams, values, props, uploader],\n );\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n handleFilesChange(files);\n // input 초기화\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [handleFilesChange],\n );\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (disabled || isUploading) return;\n\n const files = Array.from(e.dataTransfer.files);\n handleFilesChange(files);\n },\n [handleFilesChange, disabled, isUploading],\n );\n\n const handleRemove = useCallback(\n (index: number) => (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (!isMultiple) {\n (props.onValueChange as ((v: SonamuFile | File | null) => void) | undefined)?.(null);\n } else {\n const newValue = values.filter((_, i) => i !== index);\n (props.onValueChange as ((v: (SonamuFile | File)[]) => void) | undefined)?.(newValue);\n }\n },\n [values, isMultiple, props.onValueChange],\n );\n\n const handleClick = () => {\n if (!disabled && !isUploading) {\n inputRef.current?.click();\n }\n };\n\n // viewMode에 따라 적절한 사이즈 클래스 선택\n const sizeClasses = isImageView ? imageSizeClasses : fileSizeClasses;\n\n // Single 모드 렌더링\n if (!isMultiple && displayItems.length > 0) {\n const item = displayItems[0];\n return (\n <div className={cn(\"relative inline-block\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"relative flex items-center justify-center rounded-lg border-2 cursor-pointer transition-all\",\n sizeClasses[previewSize],\n isImageView\n ? \"border-transparent\"\n : \"border-dashed border-muted-foreground/25 hover:border-muted-foreground/50\",\n dragOver && \"border-primary bg-primary/5\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <>\n {isImageView ? (\n <img\n src={item.url}\n alt=\"Preview\"\n className=\"h-full w-full object-cover rounded-lg overflow-hidden\"\n />\n ) : (\n <div className=\"flex items-center gap-2 px-3 h-full w-full min-w-0 overflow-hidden\">\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(0)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </>\n )}\n </div>\n </div>\n );\n }\n\n // Multiple 모드 또는 빈 Single 모드 렌더링\n return (\n <div className={cn(\"flex flex-wrap gap-3\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n multiple={isMultiple}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n {/* 업로드된 파일들 */}\n {displayItems.map((item, index) => (\n <div key={`${item.url}-${index}`} className={cn(\"relative\", sizeClasses[previewSize])}>\n {isImageView ? (\n <div className=\"h-full w-full rounded-lg border overflow-hidden\">\n <img\n src={item.url}\n alt={`Uploaded ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n </div>\n ) : (\n <div\n className={cn(\n \"relative flex items-center gap-2 px-3 rounded-lg border-2 min-w-0 overflow-hidden\",\n \"border-dashed border-muted-foreground/25\",\n \"h-full w-full\",\n )}\n >\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(index)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </div>\n ))}\n\n {/* 추가 버튼 */}\n {canAddMore && (\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"flex items-center justify-center rounded-lg border-2 border-dashed cursor-pointer transition-all\",\n sizeClasses[previewSize],\n dragOver\n ? \"border-primary bg-primary/5\"\n : \"border-muted-foreground/25 hover:border-muted-foreground/50\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground p-2\">\n {isImageView ? <ImageIcon className=\"h-6 w-6\" /> : <UploadIcon className=\"h-6 w-6\" />}\n <span className=\"text-xs text-center\">{defaultPlaceholder}</span>\n </div>\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,EAAiB,GAA0B;CAClD,IAAM,IAAQ,EAAS,MAAM,GAAG;CAEhC,OADI,EAAM,SAAS,IAAU,KACtB,EAAM,EAAM,SAAS,GAAG,YAAY;AAC7C;AAEA,IAAM,IAA6C;CACjD,IAAI;CACJ,IAAI;CACJ,IAA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AGF,KAAe,EAAK,aACnB,kBAAC,OAAD;MAAK,WAAU;gBACZ,EAAG,sBAAsB;KACvB,CAAA;IAEJ;MAjDK,GAAG,EAAK,IAAI,GAAG,GAiDpB,CACN;GAGA,KACC,kBAAC,OAAD;IACE,SAAS;IACT,QAAQ;IACR,aAAa,MAAM;KAEjB,AADA,EAAE,eAAe,GACjB,CAAC,KAAY,CAAC,KAAe,EAAY,EAAI;IAC/C;IACA,cAAc,MAAM;KAElB,AADA,EAAE,eAAe,GACjB,EAAY,EAAK;IACnB;IACA,WAAW,EACT,oGACA,EAAY,IACZ,IACI,gCACA,+DACJ,KAAY,iCACZ,KAAe,aACjB;cAEC,IACC,kBAAC,OAAD;KAAK,WAAU;eAAf,CACE,kBAAC,GAAD,EAAa,WAAU,uBAAwB,CAAA,GAC/C,kBAAC,QAAD;MAAM,WAAU;gBAAW,EAAG,wBAAwB;KAAQ,CAAA,CAC3D;SAEL,kBAAC,OAAD;KAAK,WAAU;eAAf,CACiB,EAAd,IAAe,IAAoC,GAArC,EAAW,WAAU,UAAW,CAAqC,GACpF,kBAAC,QAAD;MAAM,WAAU;gBAAuB;KAAyB,CAAA,CAC7D;;GAEJ,CAAA;EAEJ;;AAET"}
1
+ {"version":3,"file":"file-input.js","names":[],"sources":["../../../src/components/ui/file-input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport type React from \"react\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport { FileIcon as ReactFileIcon, defaultStyles } from \"react-file-icon\";\nimport ImageIcon from \"~icons/lucide/image\";\nimport Loader2Icon from \"~icons/lucide/loader2\";\nimport UploadIcon from \"~icons/lucide/upload\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type SonamuFile, type UploadParams } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\nimport { type RCKeys } from \"@/i18n/rc-keys\";\nimport { cn, useObjectUrls } from \"@/lib/utils\";\n\nimport { Button } from \"./button\";\n\nexport type PreviewSize = \"sm\" | \"md\" | \"lg\" | \"xl\";\n\nfunction isFile(value: SonamuFile | File): value is File {\n return Object.prototype.toString.call(value) === \"[object File]\";\n}\n\nfunction getFileExtension(filename: string): string {\n const parts = filename.split(\".\");\n if (parts.length < 2) return \"\";\n return parts[parts.length - 1].toLowerCase();\n}\n\nconst fileIconSizes = {\n sm: 14,\n md: 18,\n lg: 22,\n xl: 26,\n};\n\nconst fileIconStyles = new Map<string, Partial<React.ComponentProps<typeof ReactFileIcon>>>(\n Object.entries(defaultStyles),\n);\n\nfunction FileTypeIcon({ filename, size = \"md\" }: { filename: string; size?: PreviewSize }) {\n const ext = getFileExtension(filename);\n const styleProps = fileIconStyles.get(ext) ?? {};\n\n return (\n <div className=\"shrink-0 self-center\" style={{ width: fileIconSizes[size], marginTop: -2 }}>\n <ReactFileIcon extension={ext || undefined} {...styleProps} />\n </div>\n );\n}\n\n// 이미지용: 정사각형\nconst imageSizeClasses = {\n sm: \"w-20 h-20\",\n md: \"w-32 h-32\",\n lg: \"w-40 h-40\",\n xl: \"w-48 h-48\",\n};\n\n// 파일용: 가로로 긴 직사각형\nconst fileSizeClasses = {\n sm: \"w-48 h-12\",\n md: \"w-80 h-16\",\n lg: \"w-96 h-20\",\n xl: \"w-[28rem] h-24\",\n};\n\ntype BaseProps = {\n uploadMode: \"eager\" | \"lazy\";\n viewMode: \"image\" | \"file\";\n placeholder?: string;\n accept?: string;\n disabled?: boolean;\n className?: string;\n previewSize?: PreviewSize;\n uploadParams?: UploadParams;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n};\n\ntype SingleModeProps = BaseProps & {\n multiple?: false;\n value: SonamuFile | File | null;\n onValueChange?: (value: SonamuFile | File | null) => void;\n};\n\ntype MultipleModeProps = BaseProps & {\n multiple: true;\n value: (SonamuFile | File)[] | null;\n onValueChange?: (value: (SonamuFile | File)[]) => void;\n maxFiles?: number;\n};\n\nexport type FileInputProps = SingleModeProps | MultipleModeProps;\n\nexport function FileInput(props: FileInputProps) {\n const {\n placeholder,\n disabled = false,\n className,\n previewSize = \"md\",\n uploadMode,\n viewMode,\n uploadParams,\n onBlur,\n } = props;\n\n const { uploader, SD } = useSonamuBaseContext<RCKeys>();\n\n const isMultiple = props.multiple ?? false;\n const isImageView = viewMode === \"image\";\n\n // viewMode에 따라 accept 자동 설정\n const accept = props.accept ?? (isImageView ? \"image/*\" : \"*/*\");\n\n const inputRef = useRef<HTMLInputElement>(null);\n const [isUploading, setIsUploading] = useState(false);\n const [dragOver, setDragOver] = useState(false);\n\n // 기본 placeholder 설정\n const defaultPlaceholder =\n placeholder ??\n `${isImageView ? SD(\"rc.fileInput.imagePlaceholder\") : SD(\"rc.fileInput.filePlaceholder\")} URL${isMultiple ? \"S\" : \"\"}`;\n\n // 입력 정규화: 내부적으로 배열로 통일\n const values: Array<SonamuFile | File> = useMemo(() => {\n if (props.multiple !== true) {\n const singleValue = props.value;\n return singleValue ? [singleValue] : [];\n }\n return props.value ?? [];\n }, [props.multiple, props.value]);\n\n // File 객체만 추출\n const fileObjects = useMemo(() => values.filter(isFile), [values]);\n\n // File 객체는 useObjectUrls로 안전하게 blob URL 생성 (자동 메모리 해제)\n const blobUrls = useObjectUrls(fileObjects);\n\n // 최종 display 데이터: 원래 순서를 유지하면서 File은 blob URL로, SonamuFile은 그대로\n const displayItems = values.map((v) => {\n if (isFile(v)) {\n const index = fileObjects.indexOf(v);\n return {\n url: blobUrls[index],\n name: v.name,\n isPending: true,\n };\n }\n // SonamuFile\n return {\n url: v.url,\n name: v.name,\n isPending: false,\n };\n });\n\n const maxFiles = props.multiple === true ? (props.maxFiles ?? 10) : 1;\n const totalCount = values.length;\n const canAddMore = totalCount < maxFiles;\n\n const handleFilesChange = useCallback(\n async (files: File[]) => {\n if (files.length === 0 || disabled) return;\n\n // maxFiles 체크\n const remainingSlots = maxFiles - totalCount;\n if (remainingSlots <= 0) {\n const maxFilesTranslation = SD(\"rc.fileInput.maxFilesExceeded\");\n alert(\n isFunction(maxFilesTranslation) ? maxFilesTranslation(maxFiles) : maxFilesTranslation,\n );\n return;\n }\n\n const filesToAdd = files.slice(0, remainingSlots);\n\n // Eager 모드: 즉시 업로드\n if (uploadMode === \"eager\") {\n setIsUploading(true);\n try {\n const uploadedFiles = await uploader(filesToAdd, uploadParams);\n\n if (props.multiple === true) {\n // Multiple 파일 업로드\n const finalValues = [...values, ...uploadedFiles];\n props.onValueChange?.(finalValues);\n } else {\n // Single 파일 업로드\n props.onValueChange?.(uploadedFiles[0] ?? null);\n }\n } catch (error) {\n console.error(\"Upload failed:\", error);\n alert(SD(\"rc.fileInput.uploadFailed\"));\n } finally {\n setIsUploading(false);\n }\n } else {\n // Lazy 모드: File 객체 그대로 전달\n if (props.multiple === true) {\n const finalValues = [...values, ...filesToAdd];\n props.onValueChange?.(finalValues);\n } else {\n props.onValueChange?.(filesToAdd[0] ?? null);\n }\n }\n },\n [disabled, totalCount, maxFiles, uploadMode, uploadParams, values, props, uploader, SD],\n );\n\n const handleInputChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = Array.from(e.target.files || []);\n handleFilesChange(files);\n // input 초기화\n if (inputRef.current) {\n inputRef.current.value = \"\";\n }\n },\n [handleFilesChange],\n );\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (disabled || isUploading) return;\n\n const files = Array.from(e.dataTransfer.files);\n handleFilesChange(files);\n },\n [handleFilesChange, disabled, isUploading],\n );\n\n const handleRemove = useCallback(\n (index: number) => (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (props.multiple !== true) {\n props.onValueChange?.(null);\n } else {\n const newValue = values.filter((_, i) => i !== index);\n props.onValueChange?.(newValue);\n }\n },\n [values, props],\n );\n\n const handleClick = () => {\n if (!disabled && !isUploading) {\n inputRef.current?.click();\n }\n };\n\n // viewMode에 따라 적절한 사이즈 클래스 선택\n const sizeClasses = isImageView ? imageSizeClasses : fileSizeClasses;\n\n // Single 모드 렌더링\n if (!isMultiple && displayItems.length > 0) {\n const item = displayItems[0];\n return (\n <div className={cn(\"relative inline-block\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"relative flex items-center justify-center rounded-lg border-2 cursor-pointer transition-all\",\n sizeClasses[previewSize],\n isImageView\n ? \"border-transparent\"\n : \"border-dashed border-muted-foreground/25 hover:border-muted-foreground/50\",\n dragOver && \"border-primary bg-primary/5\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <>\n {isImageView ? (\n <img\n src={item.url}\n alt=\"Preview\"\n className=\"h-full w-full object-cover rounded-lg overflow-hidden\"\n />\n ) : (\n <div className=\"flex items-center gap-2 px-3 h-full w-full min-w-0 overflow-hidden\">\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(0)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </>\n )}\n </div>\n </div>\n );\n }\n\n // Multiple 모드 또는 빈 Single 모드 렌더링\n return (\n <div className={cn(\"flex flex-wrap gap-3\", className)}>\n <input\n ref={inputRef}\n type=\"file\"\n accept={accept}\n multiple={isMultiple}\n onChange={handleInputChange}\n onBlur={onBlur}\n disabled={disabled || isUploading}\n className=\"sr-only\"\n />\n\n {/* 업로드된 파일들 */}\n {displayItems.map((item, index) => (\n <div key={`${item.url}-${index}`} className={cn(\"relative\", sizeClasses[previewSize])}>\n {isImageView ? (\n <div className=\"h-full w-full rounded-lg border overflow-hidden\">\n <img\n src={item.url}\n alt={`Uploaded ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n </div>\n ) : (\n <div\n className={cn(\n \"relative flex items-center gap-2 px-3 rounded-lg border-2 min-w-0 overflow-hidden\",\n \"border-dashed border-muted-foreground/25\",\n \"h-full w-full\",\n )}\n >\n <FileTypeIcon filename={item.name} size={previewSize} />\n <span\n className={cn(\n \"text-xs truncate min-w-0\",\n item.isPending ? \"w-[140px] shrink-0\" : \"flex-1\",\n )}\n >\n {item.name}\n </span>\n {item.isPending && (\n <span className=\"px-2 py-0.5 bg-yellow-500/90 text-white text-xs rounded whitespace-nowrap shrink-0\">\n {SD(\"rc.fileInput.pending\")}\n </span>\n )}\n </div>\n )}\n {!disabled && (\n <Button\n type=\"button\"\n variant=\"destructive\"\n size=\"xs\"\n className=\"absolute -top-2 -right-2 h-6 w-6 rounded-full p-0\"\n onClick={handleRemove(index)}\n icon={<XIcon />}\n />\n )}\n {/* 이미지 모드일 때만 하단에 대기중 배지 표시 */}\n {isImageView && item.isPending && (\n <div className=\"absolute bottom-2 left-2 right-2 mx-auto max-w-[calc(100%-1rem)] px-2 py-1 bg-yellow-500/90 text-white text-xs rounded text-center truncate\">\n {SD(\"rc.fileInput.pending\")}\n </div>\n )}\n </div>\n ))}\n\n {/* 추가 버튼 */}\n {canAddMore && (\n <div\n onClick={handleClick}\n onDrop={handleDrop}\n onDragOver={(e) => {\n e.preventDefault();\n !disabled && !isUploading && setDragOver(true);\n }}\n onDragLeave={(e) => {\n e.preventDefault();\n setDragOver(false);\n }}\n className={cn(\n \"flex items-center justify-center rounded-lg border-2 border-dashed cursor-pointer transition-all\",\n sizeClasses[previewSize],\n dragOver\n ? \"border-primary bg-primary/5\"\n : \"border-muted-foreground/25 hover:border-muted-foreground/50\",\n disabled && \"opacity-50 cursor-not-allowed\",\n isUploading && \"cursor-wait\",\n )}\n >\n {isUploading ? (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground\">\n <Loader2Icon className=\"h-6 w-6 animate-spin\" />\n <span className=\"text-xs\">{SD(\"rc.fileInput.uploading\")}</span>\n </div>\n ) : (\n <div className=\"flex flex-col items-center gap-2 text-muted-foreground p-2\">\n {isImageView ? <ImageIcon className=\"h-6 w-6\" /> : <UploadIcon className=\"h-6 w-6\" />}\n <span className=\"text-xs text-center\">{defaultPlaceholder}</span>\n </div>\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAS,EAAO,GAAyC;CACvD,OAAO,OAAO,UAAU,SAAS,KAAK,CAAK,MAAM;AACnD;AAEA,SAAS,EAAiB,GAA0B;CAClD,IAAM,IAAQ,EAAS,MAAM,GAAG;CAEhC,OADI,EAAM,SAAS,IAAU,KACtB,EAAM,EAAM,SAAS,GAAG,YAAY;AAC7C;AAEA,IAAM,IAAgB;CACpB,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN,GAEM,IAAiB,IAAI,IACzB,OAAO,QAAQ,CAAa,CAC9B;AAEA,SAAS,EAAa,EAAE,aAAU,UAAO,QAAkD;CACzF,IAAM,IAAM,EAAiB,CAAQ,G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S,EAAa,CAAK;MAC3B,MAAM,kBAAC,GAAD,CAAQ,CAAA;KACf,CAAA;KAGF,KAAe,EAAK,aACnB,kBAAC,OAAD;MAAK,WAAU;gBACZ,EAAG,sBAAsB;KACvB,CAAA;IAEJ;MAjDK,GAAG,EAAK,IAAI,GAAG,GAiDpB,CACN;GAGA,KACC,kBAAC,OAAD;IACE,SAAS;IACT,QAAQ;IACR,aAAa,MAAM;KAEjB,AADA,EAAE,eAAe,GACjB,CAAC,KAAY,CAAC,KAAe,EAAY,EAAI;IAC/C;IACA,cAAc,MAAM;KAElB,AADA,EAAE,eAAe,GACjB,EAAY,EAAK;IACnB;IACA,WAAW,EACT,oGACA,EAAY,IACZ,IACI,gCACA,+DACJ,KAAY,iCACZ,KAAe,aACjB;cAEC,IACC,kBAAC,OAAD;KAAK,WAAU;eAAf,CACE,kBAAC,GAAD,EAAa,WAAU,uBAAwB,CAAA,GAC/C,kBAAC,QAAD;MAAM,WAAU;gBAAW,EAAG,wBAAwB;KAAQ,CAAA,CAC3D;SAEL,kBAAC,OAAD;KAAK,WAAU;eAAf,CACiB,EAAd,IAAe,IAAoC,GAArC,EAAW,WAAU,UAAW,CAAqC,GACpF,kBAAC,QAAD;MAAM,WAAU;gBAAuB;KAAyB,CAAA,CAC7D;;GAEJ,CAAA;EAEJ;;AAET"}
@@ -2,38 +2,39 @@ import { cn as e } from "../../lib/utils.js";
2
2
  import t from "../../_virtual/~icons/lucide/x.js";
3
3
  import * as n from "react";
4
4
  import { jsx as r, jsxs as i } from "react/jsx-runtime";
5
+ import { isFunction as a } from "radashi";
5
6
  //#region src/components/ui/input.tsx
6
- var a = n.forwardRef(({ className: a, type: o, onValueChange: s, onChange: c, clearable: l = !1, ...u }, d) => {
7
- let f = n.useRef(null), p = n.useCallback((e) => {
8
- f.current = e, typeof d == "function" ? d(e) : d && (d.current = e);
9
- }, [d]), m = u.value !== void 0, [h, g] = n.useState(() => String(u.defaultValue ?? "").length > 0), _ = m ? String(u.value ?? "").length > 0 : h, v = (e) => {
10
- m || g(e.target.value.length > 0), s?.(e.target.value), c?.(e);
11
- }, y = () => {
12
- let e = f.current;
13
- e && ((Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(e, ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.focus()), m || g(!1);
14
- }, b = l && _ && !u.disabled && !u.readOnly, x = /* @__PURE__ */ r("input", {
15
- type: o,
7
+ var o = n.forwardRef(({ className: o, type: s, onValueChange: c, onChange: l, clearable: u = !1, ...d }, f) => {
8
+ let p = n.useRef(null), m = n.useCallback((e) => {
9
+ p.current = e, a(f) ? f(e) : f && (f.current = e);
10
+ }, [f]), h = d.value !== void 0, [g, _] = n.useState(() => String(d.defaultValue ?? "").length > 0), v = h ? String(d.value ?? "").length > 0 : g, y = (e) => {
11
+ h || _(e.target.value.length > 0), c?.(e.target.value), l?.(e);
12
+ }, b = () => {
13
+ let e = p.current;
14
+ e && ((Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(e, ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.focus()), h || _(!1);
15
+ }, x = u && v && !d.disabled && !d.readOnly, S = /* @__PURE__ */ r("input", {
16
+ type: s,
16
17
  "data-slot": "input",
17
- className: e("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background 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", "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]", "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", l && "pr-8", a),
18
- ref: p,
19
- ...u,
20
- onChange: v
18
+ className: e("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background 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", "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]", "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", u && "pr-8", o),
19
+ ref: m,
20
+ ...d,
21
+ onChange: y
21
22
  });
22
- return l ? /* @__PURE__ */ i("div", {
23
+ return u ? /* @__PURE__ */ i("div", {
23
24
  className: "relative w-full",
24
- children: [x, b && /* @__PURE__ */ r("button", {
25
+ children: [S, x && /* @__PURE__ */ r("button", {
25
26
  type: "button",
26
27
  tabIndex: -1,
27
28
  "aria-label": "Clear",
28
29
  onMouseDown: (e) => e.preventDefault(),
29
- onClick: y,
30
+ onClick: b,
30
31
  className: "absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center text-muted-foreground opacity-60 hover:opacity-100 transition-opacity cursor-pointer",
31
32
  children: /* @__PURE__ */ r(t, { className: "h-4 w-4" })
32
33
  })]
33
- }) : x;
34
+ }) : S;
34
35
  });
35
- a.displayName = "Input";
36
+ o.displayName = "Input";
36
37
  //#endregion
37
- export { a as Input };
38
+ export { o as Input };
38
39
 
39
40
  //# sourceMappingURL=input.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"input.js","names":[],"sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import * as React from \"react\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type Override } from \"../../lib/types\";\nimport { cn } from \"../../lib/utils\";\n\nexport type InputProps = Override<\n React.ComponentProps<\"input\">,\n {\n onValueChange?: (value: string) => void;\n /**\n * 활성화 시 내용이 채워지면 오른쪽에 X 아이콘이 뜨고, 누르면 내용을 초기화한다.\n * controlled/uncontrolled 입력 모두 지원한다.\n */\n clearable?: boolean;\n }\n>;\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n ({ className, type, onValueChange, onChange, clearable = false, ...props }, ref) => {\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // 전달된 ref와 내부 ref를 함께 채우는 콜백 ref\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref],\n );\n\n // controlled면 value로, uncontrolled면 내부 상태로 내용 유무를 판단한다.\n const isControlled = props.value !== undefined;\n const [uncontrolledHasValue, setUncontrolledHasValue] = React.useState(\n () => String(props.defaultValue ?? \"\").length > 0,\n );\n const hasValue = isControlled ? String(props.value ?? \"\").length > 0 : uncontrolledHasValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setUncontrolledHasValue(e.target.value.length > 0);\n }\n onValueChange?.(e.target.value);\n onChange?.(e);\n };\n\n const handleClear = () => {\n const node = innerRef.current;\n if (node) {\n // native value setter로 값을 비우고 input 이벤트를 dispatch하면\n // React의 value tracker가 변화를 인식해 controlled/uncontrolled 모두에서 onChange가 발화된다.\n const nativeInputValueSetter = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n nativeInputValueSetter?.call(node, \"\");\n node.dispatchEvent(new Event(\"input\", { bubbles: true }));\n node.focus();\n }\n if (!isControlled) {\n setUncontrolledHasValue(false);\n }\n };\n\n const showClear = clearable && hasValue && !props.disabled && !props.readOnly;\n\n const inputEl = (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n \"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background 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\",\n \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n \"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive\",\n clearable && \"pr-8\",\n className,\n )}\n ref={setRefs}\n {...props}\n onChange={handleChange}\n />\n );\n\n if (!clearable) {\n return inputEl;\n }\n\n return (\n <div className=\"relative w-full\">\n {inputEl}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={handleClear}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center text-muted-foreground opacity-60 hover:opacity-100 transition-opacity cursor-pointer\"\n >\n <XIcon className=\"h-4 w-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInput.displayName = \"Input\";\n\nexport { Input };\n"],"mappings":";;;;;AAkBA,IAAM,IAAQ,EAAM,YACjB,EAAE,cAAW,SAAM,kBAAe,aAAU,eAAY,IAAO,GAAG,KAAS,MAAQ;CAClF,IAAM,IAAW,EAAM,OAAyB,IAAI,GAG9C,IAAU,EAAM,aACnB,MAAkC;EAEjC,AADA,EAAS,UAAU,GACf,OAAO,KAAQ,aACjB,EAAI,CAAI,IACC,MACT,EAAI,UAAU;CAElB,GACA,CAAC,CAAG,CACN,GAGM,IAAe,EAAM,UAAU,KAAA,GAC/B,CAAC,GAAsB,KAA2B,EAAM,eACtD,OAAO,EAAM,gBAAgB,EAAE,EAAE,SAAS,CAClD,GACM,IAAW,IAAe,OAAO,EAAM,SAAS,EAAE,EAAE,SAAS,IAAI,GAEjE,KAAgB,MAA2C;EAK/D,AAJK,KACH,EAAwB,EAAE,OAAO,MAAM,SAAS,CAAC,GAEnD,IAAgB,EAAE,OAAO,KAAK,GAC9B,IAAW,CAAC;CACd,GAEM,UAAoB;EACxB,IAAM,IAAO,EAAS;EAYtB,AAXI,OAG6B,OAAO,yBACpC,OAAO,iBAAiB,WACxB,OACF,GAAG,MACqB,KAAK,GAAM,EAAE,GACrC,EAAK,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,GAAK,CAAC,CAAC,GACxD,EAAK,MAAM,IAER,KACH,EAAwB,EAAK;CAEjC,GAEM,IAAY,KAAa,KAAY,CAAC,EAAM,YAAY,CAAC,EAAM,UAE/D,IACJ,kBAAC,SAAD;EACQ;EACN,aAAU;EACV,WAAW,EACT,8bACA,iFACA,0GACA,KAAa,QACb,CACF;EACA,KAAK;EACL,GAAI;EACJ,UAAU;CACX,CAAA;CAOH,OAJK,IAKH,kBAAC,OAAD;EAAK,WAAU;YAAf,CACG,GACA,KACC,kBAAC,UAAD;GACE,MAAK;GACL,UAAU;GACV,cAAW;GACX,cAAc,MAAM,EAAE,eAAe;GACrC,SAAS;GACT,WAAU;aAEV,kBAAC,GAAD,EAAO,WAAU,UAAW,CAAA;EACtB,CAAA,CAEP;MAlBE;AAoBX,CACF;AACA,EAAM,cAAc"}
1
+ {"version":3,"file":"input.js","names":[],"sources":["../../../src/components/ui/input.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport * as React from \"react\";\nimport XIcon from \"~icons/lucide/x\";\n\nimport { type Override } from \"../../lib/types\";\nimport { cn } from \"../../lib/utils\";\n\nexport type InputProps = Override<\n React.ComponentProps<\"input\">,\n {\n onValueChange?: (value: string) => void;\n /**\n * 활성화 시 내용이 채워지면 오른쪽에 X 아이콘이 뜨고, 누르면 내용을 초기화한다.\n * controlled/uncontrolled 입력 모두 지원한다.\n */\n clearable?: boolean;\n }\n>;\n\nconst Input = React.forwardRef<HTMLInputElement, InputProps>(\n ({ className, type, onValueChange, onChange, clearable = false, ...props }, ref) => {\n const innerRef = React.useRef<HTMLInputElement>(null);\n\n // 전달된 ref와 내부 ref를 함께 채우는 콜백 ref\n const setRefs = React.useCallback(\n (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (isFunction(ref)) {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref],\n );\n\n // controlled면 value로, uncontrolled면 내부 상태로 내용 유무를 판단한다.\n const isControlled = props.value !== undefined;\n const [uncontrolledHasValue, setUncontrolledHasValue] = React.useState(\n () => String(props.defaultValue ?? \"\").length > 0,\n );\n const hasValue = isControlled ? String(props.value ?? \"\").length > 0 : uncontrolledHasValue;\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!isControlled) {\n setUncontrolledHasValue(e.target.value.length > 0);\n }\n onValueChange?.(e.target.value);\n onChange?.(e);\n };\n\n const handleClear = () => {\n const node = innerRef.current;\n if (node) {\n // native value setter로 값을 비우고 input 이벤트를 dispatch하면\n // React의 value tracker가 변화를 인식해 controlled/uncontrolled 모두에서 onChange가 발화된다.\n const nativeInputValueSetter = Object.getOwnPropertyDescriptor(\n window.HTMLInputElement.prototype,\n \"value\",\n )?.set;\n nativeInputValueSetter?.call(node, \"\");\n node.dispatchEvent(new Event(\"input\", { bubbles: true }));\n node.focus();\n }\n if (!isControlled) {\n setUncontrolledHasValue(false);\n }\n };\n\n const showClear = clearable && hasValue && !props.disabled && !props.readOnly;\n\n const inputEl = (\n <input\n type={type}\n data-slot=\"input\"\n className={cn(\n \"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border px-3 py-1 text-base bg-input-background 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\",\n \"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n \"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive\",\n clearable && \"pr-8\",\n className,\n )}\n ref={setRefs}\n {...props}\n onChange={handleChange}\n />\n );\n\n if (!clearable) {\n return inputEl;\n }\n\n return (\n <div className=\"relative w-full\">\n {inputEl}\n {showClear && (\n <button\n type=\"button\"\n tabIndex={-1}\n aria-label=\"Clear\"\n onMouseDown={(e) => e.preventDefault()}\n onClick={handleClear}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center text-muted-foreground opacity-60 hover:opacity-100 transition-opacity cursor-pointer\"\n >\n <XIcon className=\"h-4 w-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInput.displayName = \"Input\";\n\nexport { Input };\n"],"mappings":";;;;;;AAmBA,IAAM,IAAQ,EAAM,YACjB,EAAE,cAAW,SAAM,kBAAe,aAAU,eAAY,IAAO,GAAG,KAAS,MAAQ;CAClF,IAAM,IAAW,EAAM,OAAyB,IAAI,GAG9C,IAAU,EAAM,aACnB,MAAkC;EAEjC,AADA,EAAS,UAAU,GACf,EAAW,CAAG,IAChB,EAAI,CAAI,IACC,MACT,EAAI,UAAU;CAElB,GACA,CAAC,CAAG,CACN,GAGM,IAAe,EAAM,UAAU,KAAA,GAC/B,CAAC,GAAsB,KAA2B,EAAM,eACtD,OAAO,EAAM,gBAAgB,EAAE,EAAE,SAAS,CAClD,GACM,IAAW,IAAe,OAAO,EAAM,SAAS,EAAE,EAAE,SAAS,IAAI,GAEjE,KAAgB,MAA2C;EAK/D,AAJK,KACH,EAAwB,EAAE,OAAO,MAAM,SAAS,CAAC,GAEnD,IAAgB,EAAE,OAAO,KAAK,GAC9B,IAAW,CAAC;CACd,GAEM,UAAoB;EACxB,IAAM,IAAO,EAAS;EAYtB,AAXI,OAG6B,OAAO,yBACpC,OAAO,iBAAiB,WACxB,OACF,GAAG,MACqB,KAAK,GAAM,EAAE,GACrC,EAAK,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,GAAK,CAAC,CAAC,GACxD,EAAK,MAAM,IAER,KACH,EAAwB,EAAK;CAEjC,GAEM,IAAY,KAAa,KAAY,CAAC,EAAM,YAAY,CAAC,EAAM,UAE/D,IACJ,kBAAC,SAAD;EACQ;EACN,aAAU;EACV,WAAW,EACT,8bACA,iFACA,0GACA,KAAa,QACb,CACF;EACA,KAAK;EACL,GAAI;EACJ,UAAU;CACX,CAAA;CAOH,OAJK,IAKH,kBAAC,OAAD;EAAK,WAAU;YAAf,CACG,GACA,KACC,kBAAC,UAAD;GACE,MAAK;GACL,UAAU;GACV,cAAW;GACX,cAAc,MAAM,EAAE,eAAe;GACrC,SAAS;GACT,WAAU;aAEV,kBAAC,GAAD,EAAO,WAAU,UAAW,CAAA;EACtB,CAAA,CAEP;MAlBE;AAoBX,CACF;AACA,EAAM,cAAc"}
@@ -25,25 +25,37 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
25
25
  start: 2020,
26
26
  end: 2030
27
27
  }, defaultRangeMode: y = !1 }) {
28
- let { SD: b } = t(), [x, S] = o.useState(!1), [C, w] = o.useState(y), [T, E] = o.useState(), [D, O] = o.useState(), [k, A] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), [j, M] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), [N, P] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), F = o.useMemo(() => Array.from({ length: v.end - v.start + 1 }, (e, t) => v.start + t), [v.start, v.end]);
29
- o.useEffect(() => {
30
- x && (p?.type === "range" ? (w(!0), O({
31
- from: p.from,
32
- to: p.to
33
- }), E(void 0), M(p.from.getFullYear()), P(p.to.getFullYear())) : p?.type === "single" ? (w(!1), E(p.date), O(void 0), A(p.date.getFullYear())) : (w(y), E(void 0), O(void 0), A((/* @__PURE__ */ new Date()).getFullYear()), M((/* @__PURE__ */ new Date()).getFullYear()), P((/* @__PURE__ */ new Date()).getFullYear())));
34
- }, [
35
- x,
36
- p,
37
- y
38
- ]);
39
- let I = () => p ? p.type === "single" ? l(p.date, g) : `${l(p.from, g)} - ${l(p.to, g)}` : h ?? `- ${l(/* @__PURE__ */ new Date(), g)}`, L = (e) => {
28
+ let { SD: b } = t(), [x, S] = o.useState(!1), [C, w] = o.useState(y), [T, E] = o.useState(), [D, O] = o.useState(), [k, A] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), [j, M] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), [N, P] = o.useState((/* @__PURE__ */ new Date()).getFullYear()), [F, I] = o.useState(() => ({
29
+ value: p,
30
+ defaultRangeMode: y
31
+ })), L = o.useMemo(() => Array.from({ length: v.end - v.start + 1 }, (e, t) => v.start + t), [v.start, v.end]), R = (e, t) => {
32
+ if (e?.type === "range") w(!0), O({
33
+ from: e.from,
34
+ to: e.to
35
+ }), E(void 0), M(e.from.getFullYear()), P(e.to.getFullYear());
36
+ else if (e?.type === "single") w(!1), E(e.date), O(void 0), A(e.date.getFullYear());
37
+ else {
38
+ let e = (/* @__PURE__ */ new Date()).getFullYear();
39
+ w(t), E(void 0), O(void 0), A(e), M(e), P(e);
40
+ }
41
+ };
42
+ x && (F.value !== p || F.defaultRangeMode !== y) && (I({
43
+ value: p,
44
+ defaultRangeMode: y
45
+ }), R(p, y));
46
+ let z = (e) => {
47
+ e && (I({
48
+ value: p,
49
+ defaultRangeMode: y
50
+ }), R(p, y)), S(e);
51
+ }, B = () => p ? p.type === "single" ? l(p.date, g) : `${l(p.from, g)} - ${l(p.to, g)}` : h ?? `- ${l(/* @__PURE__ */ new Date(), g)}`, V = (e) => {
40
52
  w(e), e ? E(void 0) : O(void 0);
41
53
  };
42
54
  return /* @__PURE__ */ s("div", {
43
55
  className: "flex items-center gap-4",
44
56
  children: /* @__PURE__ */ c(n, {
45
57
  open: x,
46
- onOpenChange: S,
58
+ onOpenChange: z,
47
59
  children: [/* @__PURE__ */ s(i, {
48
60
  asChild: !0,
49
61
  children: /* @__PURE__ */ c(e, {
@@ -51,7 +63,7 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
51
63
  className: `gap-2 h-8 text-xs ${_}`,
52
64
  children: [
53
65
  /* @__PURE__ */ s(d, { className: "h-4 w-4" }),
54
- I(),
66
+ B(),
55
67
  /* @__PURE__ */ s(f, { className: "h-4 w-4" })
56
68
  ]
57
69
  })
@@ -66,13 +78,13 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
66
78
  children: [/* @__PURE__ */ s(e, {
67
79
  variant: C ? "outline" : "default",
68
80
  size: "sm",
69
- onClick: () => L(!1),
81
+ onClick: () => V(!1),
70
82
  className: "flex-1 h-7 text-xs",
71
83
  children: b("rc.monthPickerMultiple.singleDate")
72
84
  }), /* @__PURE__ */ s(e, {
73
85
  variant: C ? "default" : "outline",
74
86
  size: "sm",
75
- onClick: () => L(!0),
87
+ onClick: () => V(!0),
76
88
  className: "flex-1 h-7 text-xs",
77
89
  children: b("rc.monthPickerMultiple.dateRange")
78
90
  })]
@@ -93,7 +105,7 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
93
105
  onValueChange: (e) => {
94
106
  e !== void 0 && M(e);
95
107
  },
96
- items: F.map((e) => ({
108
+ items: L.map((e) => ({
97
109
  value: e,
98
110
  label: String(e),
99
111
  disabled: D?.to ? e > D.to.getFullYear() : !1
@@ -138,7 +150,7 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
138
150
  onValueChange: (e) => {
139
151
  e !== void 0 && P(e);
140
152
  },
141
- items: F.map((e) => ({
153
+ items: L.map((e) => ({
142
154
  value: e,
143
155
  label: String(e),
144
156
  disabled: D?.from ? e < D.from.getFullYear() : !1
@@ -178,7 +190,7 @@ function d({ CalendarIcon: d, ChevronDownIcon: f, value: p, onValueChange: m, pl
178
190
  onValueChange: (e) => {
179
191
  e !== void 0 && A(e);
180
192
  },
181
- items: F.map((e) => ({
193
+ items: L.map((e) => ({
182
194
  value: e,
183
195
  label: String(e)
184
196
  })),
@@ -1 +1 @@
1
- {"version":3,"file":"month-picker-multiple.js","names":[],"sources":["../../../src/components/ui/month-picker-multiple.tsx"],"sourcesContent":["\"use client\";\n\nimport { format } from \"date-fns\";\nimport * as React from \"react\";\nimport { type DateRange } from \"react-day-picker\";\n\nimport { useSonamuBaseContext } from \"@/contexts\";\n\nimport { Button } from \"./button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Select } from \"./select/select\";\n\n/** 단일 월 또는 월 범위 값 */\nexport type MonthPickerValue =\n | { type: \"single\"; date: Date }\n | { type: \"range\"; from: Date; to: Date };\n\ninterface MonthPickerMultipleProps {\n /** Calendar icon component */\n CalendarIcon: React.ComponentType<{ className?: string }>;\n /** ChevronDown icon component */\n ChevronDownIcon: React.ComponentType<{ className?: string }>;\n /** Current value */\n value?: MonthPickerValue;\n /** Callback when value changes */\n onValueChange?: (value: MonthPickerValue | undefined) => void;\n /** Placeholder text when no value */\n placeholder?: string;\n /** Date format string for display */\n dateFormat?: string;\n /** Custom className for trigger button */\n className?: string;\n /** Year range for selection */\n yearRange?: { start: number; end: number };\n /** Default to range mode when opening */\n defaultRangeMode?: boolean;\n}\n\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nexport function MonthPickerMultiple({\n CalendarIcon,\n ChevronDownIcon,\n value,\n onValueChange,\n placeholder,\n dateFormat = \"MMM/yyyy\",\n className = \"\",\n yearRange = { start: 2020, end: 2030 },\n defaultRangeMode = false,\n}: MonthPickerMultipleProps) {\n const { SD } = useSonamuBaseContext();\n\n // Popover open state\n const [isOpen, setIsOpen] = React.useState(false);\n\n // Temp states (managed internally)\n const [tempIsRangeMode, setTempIsRangeMode] = React.useState(defaultRangeMode);\n const [tempDate, setTempDate] = React.useState<Date | undefined>();\n const [tempDateRange, setTempDateRange] = React.useState<DateRange | undefined>();\n const [tempYear, setTempYear] = React.useState(new Date().getFullYear());\n const [tempRangeStartYear, setTempRangeStartYear] = React.useState(new Date().getFullYear());\n const [tempRangeEndYear, setTempRangeEndYear] = React.useState(new Date().getFullYear());\n\n const years = React.useMemo(\n () =>\n Array.from({ length: yearRange.end - yearRange.start + 1 }, (_, i) => yearRange.start + i),\n [yearRange.start, yearRange.end],\n );\n\n // Initialize temp states when popover opens\n React.useEffect(() => {\n if (isOpen) {\n if (value?.type === \"range\") {\n setTempIsRangeMode(true);\n setTempDateRange({ from: value.from, to: value.to });\n setTempDate(undefined);\n setTempRangeStartYear(value.from.getFullYear());\n setTempRangeEndYear(value.to.getFullYear());\n } else if (value?.type === \"single\") {\n setTempIsRangeMode(false);\n setTempDate(value.date);\n setTempDateRange(undefined);\n setTempYear(value.date.getFullYear());\n } else {\n setTempIsRangeMode(defaultRangeMode);\n setTempDate(undefined);\n setTempDateRange(undefined);\n setTempYear(new Date().getFullYear());\n setTempRangeStartYear(new Date().getFullYear());\n setTempRangeEndYear(new Date().getFullYear());\n }\n }\n }, [isOpen, value, defaultRangeMode]);\n\n const getDisplayDate = () => {\n if (!value) {\n return placeholder ?? `- ${format(new Date(), dateFormat)}`;\n }\n if (value.type === \"single\") {\n return format(value.date, dateFormat);\n }\n return `${format(value.from, dateFormat)} - ${format(value.to, dateFormat)}`;\n };\n\n const handleModeChange = (isRangeMode: boolean) => {\n setTempIsRangeMode(isRangeMode);\n if (isRangeMode) {\n setTempDate(undefined);\n } else {\n setTempDateRange(undefined);\n }\n };\n\n const handleSave = () => {\n let newValue: MonthPickerValue | undefined;\n\n if (tempIsRangeMode && tempDateRange?.from && tempDateRange?.to) {\n newValue = {\n type: \"range\",\n from: tempDateRange.from,\n to: tempDateRange.to,\n };\n } else if (!tempIsRangeMode && tempDate) {\n newValue = { type: \"single\", date: tempDate };\n }\n\n onValueChange?.(newValue);\n setIsOpen(false);\n };\n\n const handleCancel = () => {\n setIsOpen(false);\n };\n\n return (\n <div className=\"flex items-center gap-4\">\n <Popover open={isOpen} onOpenChange={setIsOpen}>\n <PopoverTrigger asChild>\n <Button variant=\"outline\" className={`gap-2 h-8 text-xs ${className}`}>\n <CalendarIcon className=\"h-4 w-4\" />\n {getDisplayDate()}\n <ChevronDownIcon className=\"h-4 w-4\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto p-0\" align=\"start\">\n <div className=\"p-3 border-b space-y-2\">\n <div className=\"flex gap-2\">\n <Button\n variant={!tempIsRangeMode ? \"default\" : \"outline\"}\n size=\"sm\"\n onClick={() => handleModeChange(false)}\n className=\"flex-1 h-7 text-xs\"\n >\n {SD(\"rc.monthPickerMultiple.singleDate\")}\n </Button>\n <Button\n variant={tempIsRangeMode ? \"default\" : \"outline\"}\n size=\"sm\"\n onClick={() => handleModeChange(true)}\n className=\"flex-1 h-7 text-xs\"\n >\n {SD(\"rc.monthPickerMultiple.dateRange\")}\n </Button>\n </div>\n </div>\n {tempIsRangeMode ? (\n <div className=\"flex\">\n {/* Start Date */}\n <div className=\"p-4 space-y-2\">\n <div className=\"text-xs text-muted-foreground\">\n {SD(\"rc.monthPickerMultiple.startDate\")}\n </div>\n <Select\n value={tempRangeStartYear}\n onValueChange={(value) => {\n if (value !== undefined) setTempRangeStartYear(value);\n }}\n items={years.map((year) => ({\n value: year,\n label: String(year),\n disabled: tempDateRange?.to ? year > tempDateRange.to.getFullYear() : false,\n }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => {\n const isDisabled = tempDateRange?.to\n ? tempRangeStartYear > tempDateRange.to.getFullYear() ||\n (tempRangeStartYear === tempDateRange.to.getFullYear() &&\n idx > tempDateRange.to.getMonth())\n : false;\n return (\n <Button\n key={month}\n variant={\n tempDateRange?.from?.getMonth() === idx &&\n tempDateRange?.from?.getFullYear() === tempRangeStartYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempRangeStartYear, idx, 1);\n // 이미 선택된 시작 월을 다시 클릭하면 해제\n if (\n tempDateRange?.from?.getMonth() === idx &&\n tempDateRange?.from?.getFullYear() === tempRangeStartYear\n ) {\n setTempDateRange({ from: undefined, to: tempDateRange?.to });\n } else {\n setTempDateRange({ from: newDate, to: tempDateRange?.to });\n }\n }}\n disabled={isDisabled}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n );\n })}\n </div>\n </div>\n {/* Divider */}\n <div className=\"border-r\" />\n {/* End Date */}\n <div className=\"p-4 space-y-2\">\n <div className=\"text-xs text-muted-foreground\">\n {SD(\"rc.monthPickerMultiple.endDate\")}\n </div>\n <Select\n value={tempRangeEndYear}\n onValueChange={(value) => {\n if (value !== undefined) setTempRangeEndYear(value);\n }}\n items={years.map((year) => ({\n value: year,\n label: String(year),\n disabled: tempDateRange?.from ? year < tempDateRange.from.getFullYear() : false,\n }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => {\n const isDisabled = tempDateRange?.from\n ? tempRangeEndYear < tempDateRange.from.getFullYear() ||\n (tempRangeEndYear === tempDateRange.from.getFullYear() &&\n idx < tempDateRange.from.getMonth())\n : false;\n return (\n <Button\n key={month}\n variant={\n tempDateRange?.to?.getMonth() === idx &&\n tempDateRange?.to?.getFullYear() === tempRangeEndYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempRangeEndYear, idx, 1);\n // 이미 선택된 종료 월을 다시 클릭하면 해제\n if (\n tempDateRange?.to?.getMonth() === idx &&\n tempDateRange?.to?.getFullYear() === tempRangeEndYear\n ) {\n setTempDateRange({ from: tempDateRange?.from, to: undefined });\n } else {\n setTempDateRange({ from: tempDateRange?.from, to: newDate });\n }\n }}\n disabled={isDisabled}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n );\n })}\n </div>\n </div>\n </div>\n ) : (\n <div className=\"p-4 space-y-2\">\n <Select\n value={tempYear}\n onValueChange={(value) => {\n if (value !== undefined) setTempYear(value);\n }}\n items={years.map((year) => ({ value: year, label: String(year) }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => (\n <Button\n key={month}\n variant={\n tempDate?.getMonth() === idx && tempDate?.getFullYear() === tempYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempYear, idx, 1);\n // 이미 선택된 월을 다시 클릭하면 해제\n if (tempDate?.getMonth() === idx && tempDate?.getFullYear() === tempYear) {\n setTempDate(undefined);\n } else {\n setTempDate(newDate);\n }\n }}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n ))}\n </div>\n </div>\n )}\n <div className=\"p-3 border-t flex justify-end gap-2\">\n <Button variant=\"outline\" size=\"sm\" onClick={handleCancel} className=\"h-8 text-xs\">\n {SD(\"rc.common.cancel\")}\n </Button>\n <Button variant=\"default\" size=\"sm\" onClick={handleSave} className=\"h-8 text-xs\">\n {SD(\"rc.common.save\")}\n </Button>\n </div>\n </PopoverContent>\n </Popover>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAsCA,IAAM,IAAS;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAK;AAElG,SAAgB,EAAoB,EAClC,iBACA,oBACA,UACA,kBACA,gBACA,gBAAa,YACb,eAAY,IACZ,eAAY;CAAE,OAAO;CAAM,KAAK;AAAK,GACrC,sBAAmB,MACQ;CAC3B,IAAM,EAAE,UAAO,EAAqB,GAG9B,CAAC,GAAQ,KAAa,EAAM,SAAS,EAAK,GAG1C,CAAC,GAAiB,KAAsB,EAAM,SAAS,CAAgB,GACvE,CAAC,GAAU,KAAe,EAAM,SAA2B,GAC3D,CAAC,GAAe,KAAoB,EAAM,SAAgC,GAC1E,CAAC,GAAU,KAAe,EAAM,0BAAS,IAAI,KAAK,GAAE,YAAY,CAAC,GACjE,CAAC,GAAoB,KAAyB,EAAM,0BAAS,IAAI,KAAK,GAAE,YAAY,CAAC,GACrF,CAAC,GAAkB,KAAuB,EAAM,0BAAS,IAAI,KAAK,GAAE,YAAY,CAAC,GAEjF,IAAQ,EAAM,cAEhB,MAAM,KAAK,EAAE,QAAQ,EAAU,MAAM,EAAU,QAAQ,EAAE,IAAI,GAAG,MAAM,EAAU,QAAQ,CA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,OAAD;MAAK,WAAU;gBAAf,CACE,kBAAC,GAAD;OACE,OAAO;OACP,gBAAgB,MAAU;QACxB,AAAI,MAAU,KAAA,KAAW,EAAY,CAAK;OAC5C;OACA,OAAO,EAAM,KAAK,OAAU;QAAE,OAAO;QAAM,OAAO,OAAO,CAAI;OAAE,EAAE;OACjE,WAAU;MACX,CAAA,GACD,kBAAC,OAAD;OAAK,WAAU;iBACZ,EAAO,KAAK,GAAO,MAClB,kBAAC,GAAD;QAEE,SACE,GAAU,SAAS,MAAM,KAAO,GAAU,YAAY,MAAM,IACxD,YACA;QAEN,MAAK;QACL,eAAe;SACb,IAAM,IAAU,IAAI,KAAK,GAAU,GAAK,CAAC;SAEzC,AAAI,GAAU,SAAS,MAAM,KAAO,GAAU,YAAY,MAAM,IAC9D,EAAY,KAAA,CAAS,IAErB,EAAY,CAAO;QAEvB;QACA,WAAU;kBAET;OACK,GAnBD,CAmBC,CACT;MACE,CAAA,CACF;;KAEP,kBAAC,OAAD;MAAK,WAAU;gBAAf,CACE,kBAAC,GAAD;OAAQ,SAAQ;OAAU,MAAK;OAAK,eA5LnB;QACzB,EAAU,EAAK;OACjB;OA0LqE,WAAU;iBAClE,EAAG,kBAAkB;MAChB,CAAA,GACR,kBAAC,GAAD;OAAQ,SAAQ;OAAU,MAAK;OAAK,eAhNrB;QACvB,IAAI;QAaJ,AAXI,KAAmB,GAAe,QAAQ,GAAe,KAC3D,IAAW;SACT,MAAM;SACN,MAAM,EAAc;SACpB,IAAI,EAAc;QACpB,IACS,CAAC,KAAmB,MAC7B,IAAW;SAAE,MAAM;SAAU,MAAM;QAAS,IAG9C,IAAgB,CAAQ,GACxB,EAAU,EAAK;OACjB;OAiMmE,WAAU;iBAChE,EAAG,gBAAgB;MACd,CAAA,CACL;;IACS;KACT;;CACN,CAAA;AAET"}
1
+ {"version":3,"file":"month-picker-multiple.js","names":[],"sources":["../../../src/components/ui/month-picker-multiple.tsx"],"sourcesContent":["\"use client\";\n\nimport { format } from \"date-fns\";\nimport * as React from \"react\";\nimport { type DateRange } from \"react-day-picker\";\n\nimport { useSonamuBaseContext } from \"@/contexts\";\n\nimport { Button } from \"./button\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\nimport { Select } from \"./select/select\";\n\n/** 단일 월 또는 월 범위 값 */\nexport type MonthPickerValue =\n | { type: \"single\"; date: Date }\n | { type: \"range\"; from: Date; to: Date };\n\ninterface MonthPickerMultipleProps {\n /** Calendar icon component */\n CalendarIcon: React.ComponentType<{ className?: string }>;\n /** ChevronDown icon component */\n ChevronDownIcon: React.ComponentType<{ className?: string }>;\n /** Current value */\n value?: MonthPickerValue;\n /** Callback when value changes */\n onValueChange?: (value: MonthPickerValue | undefined) => void;\n /** Placeholder text when no value */\n placeholder?: string;\n /** Date format string for display */\n dateFormat?: string;\n /** Custom className for trigger button */\n className?: string;\n /** Year range for selection */\n yearRange?: { start: number; end: number };\n /** Default to range mode when opening */\n defaultRangeMode?: boolean;\n}\n\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nexport function MonthPickerMultiple({\n CalendarIcon,\n ChevronDownIcon,\n value,\n onValueChange,\n placeholder,\n dateFormat = \"MMM/yyyy\",\n className = \"\",\n yearRange = { start: 2020, end: 2030 },\n defaultRangeMode = false,\n}: MonthPickerMultipleProps) {\n const { SD } = useSonamuBaseContext();\n\n // Popover open state\n const [isOpen, setIsOpen] = React.useState(false);\n\n // Temp states (managed internally)\n const [tempIsRangeMode, setTempIsRangeMode] = React.useState(defaultRangeMode);\n const [tempDate, setTempDate] = React.useState<Date | undefined>();\n const [tempDateRange, setTempDateRange] = React.useState<DateRange | undefined>();\n const [tempYear, setTempYear] = React.useState(new Date().getFullYear());\n const [tempRangeStartYear, setTempRangeStartYear] = React.useState(new Date().getFullYear());\n const [tempRangeEndYear, setTempRangeEndYear] = React.useState(new Date().getFullYear());\n const [draftSource, setDraftSource] = React.useState(() => ({ value, defaultRangeMode }));\n\n const years = React.useMemo(\n () =>\n Array.from({ length: yearRange.end - yearRange.start + 1 }, (_, i) => yearRange.start + i),\n [yearRange.start, yearRange.end],\n );\n\n const resetDraft = (nextValue: MonthPickerValue | undefined, nextDefaultRangeMode: boolean) => {\n if (nextValue?.type === \"range\") {\n setTempIsRangeMode(true);\n setTempDateRange({ from: nextValue.from, to: nextValue.to });\n setTempDate(undefined);\n setTempRangeStartYear(nextValue.from.getFullYear());\n setTempRangeEndYear(nextValue.to.getFullYear());\n } else if (nextValue?.type === \"single\") {\n setTempIsRangeMode(false);\n setTempDate(nextValue.date);\n setTempDateRange(undefined);\n setTempYear(nextValue.date.getFullYear());\n } else {\n const currentYear = new Date().getFullYear();\n setTempIsRangeMode(nextDefaultRangeMode);\n setTempDate(undefined);\n setTempDateRange(undefined);\n setTempYear(currentYear);\n setTempRangeStartYear(currentYear);\n setTempRangeEndYear(currentYear);\n }\n };\n\n // 열린 편집기에서 외부 값이 바뀌면 기존 effect와 동일하게 임시 상태를 다시 맞춥니다.\n if (\n isOpen &&\n (draftSource.value !== value || draftSource.defaultRangeMode !== defaultRangeMode)\n ) {\n setDraftSource({ value, defaultRangeMode });\n resetDraft(value, defaultRangeMode);\n }\n\n // 팝오버를 열 때 확정된 값을 임시 편집 상태로 복사합니다.\n const handleOpenChange = (open: boolean) => {\n if (open) {\n setDraftSource({ value, defaultRangeMode });\n resetDraft(value, defaultRangeMode);\n }\n setIsOpen(open);\n };\n\n const getDisplayDate = () => {\n if (!value) {\n return placeholder ?? `- ${format(new Date(), dateFormat)}`;\n }\n if (value.type === \"single\") {\n return format(value.date, dateFormat);\n }\n return `${format(value.from, dateFormat)} - ${format(value.to, dateFormat)}`;\n };\n\n const handleModeChange = (isRangeMode: boolean) => {\n setTempIsRangeMode(isRangeMode);\n if (isRangeMode) {\n setTempDate(undefined);\n } else {\n setTempDateRange(undefined);\n }\n };\n\n const handleSave = () => {\n let newValue: MonthPickerValue | undefined;\n\n if (tempIsRangeMode && tempDateRange?.from && tempDateRange?.to) {\n newValue = {\n type: \"range\",\n from: tempDateRange.from,\n to: tempDateRange.to,\n };\n } else if (!tempIsRangeMode && tempDate) {\n newValue = { type: \"single\", date: tempDate };\n }\n\n onValueChange?.(newValue);\n setIsOpen(false);\n };\n\n const handleCancel = () => {\n setIsOpen(false);\n };\n\n return (\n <div className=\"flex items-center gap-4\">\n <Popover open={isOpen} onOpenChange={handleOpenChange}>\n <PopoverTrigger asChild>\n <Button variant=\"outline\" className={`gap-2 h-8 text-xs ${className}`}>\n <CalendarIcon className=\"h-4 w-4\" />\n {getDisplayDate()}\n <ChevronDownIcon className=\"h-4 w-4\" />\n </Button>\n </PopoverTrigger>\n <PopoverContent className=\"w-auto p-0\" align=\"start\">\n <div className=\"p-3 border-b space-y-2\">\n <div className=\"flex gap-2\">\n <Button\n variant={!tempIsRangeMode ? \"default\" : \"outline\"}\n size=\"sm\"\n onClick={() => handleModeChange(false)}\n className=\"flex-1 h-7 text-xs\"\n >\n {SD(\"rc.monthPickerMultiple.singleDate\")}\n </Button>\n <Button\n variant={tempIsRangeMode ? \"default\" : \"outline\"}\n size=\"sm\"\n onClick={() => handleModeChange(true)}\n className=\"flex-1 h-7 text-xs\"\n >\n {SD(\"rc.monthPickerMultiple.dateRange\")}\n </Button>\n </div>\n </div>\n {tempIsRangeMode ? (\n <div className=\"flex\">\n {/* Start Date */}\n <div className=\"p-4 space-y-2\">\n <div className=\"text-xs text-muted-foreground\">\n {SD(\"rc.monthPickerMultiple.startDate\")}\n </div>\n <Select\n value={tempRangeStartYear}\n onValueChange={(nextYear) => {\n if (nextYear !== undefined) setTempRangeStartYear(nextYear);\n }}\n items={years.map((year) => ({\n value: year,\n label: String(year),\n disabled: tempDateRange?.to ? year > tempDateRange.to.getFullYear() : false,\n }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => {\n const isDisabled = tempDateRange?.to\n ? tempRangeStartYear > tempDateRange.to.getFullYear() ||\n (tempRangeStartYear === tempDateRange.to.getFullYear() &&\n idx > tempDateRange.to.getMonth())\n : false;\n return (\n <Button\n key={month}\n variant={\n tempDateRange?.from?.getMonth() === idx &&\n tempDateRange?.from?.getFullYear() === tempRangeStartYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempRangeStartYear, idx, 1);\n // 이미 선택된 시작 월을 다시 클릭하면 해제\n if (\n tempDateRange?.from?.getMonth() === idx &&\n tempDateRange?.from?.getFullYear() === tempRangeStartYear\n ) {\n setTempDateRange({ from: undefined, to: tempDateRange?.to });\n } else {\n setTempDateRange({ from: newDate, to: tempDateRange?.to });\n }\n }}\n disabled={isDisabled}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n );\n })}\n </div>\n </div>\n {/* Divider */}\n <div className=\"border-r\" />\n {/* End Date */}\n <div className=\"p-4 space-y-2\">\n <div className=\"text-xs text-muted-foreground\">\n {SD(\"rc.monthPickerMultiple.endDate\")}\n </div>\n <Select\n value={tempRangeEndYear}\n onValueChange={(nextYear) => {\n if (nextYear !== undefined) setTempRangeEndYear(nextYear);\n }}\n items={years.map((year) => ({\n value: year,\n label: String(year),\n disabled: tempDateRange?.from ? year < tempDateRange.from.getFullYear() : false,\n }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => {\n const isDisabled = tempDateRange?.from\n ? tempRangeEndYear < tempDateRange.from.getFullYear() ||\n (tempRangeEndYear === tempDateRange.from.getFullYear() &&\n idx < tempDateRange.from.getMonth())\n : false;\n return (\n <Button\n key={month}\n variant={\n tempDateRange?.to?.getMonth() === idx &&\n tempDateRange?.to?.getFullYear() === tempRangeEndYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempRangeEndYear, idx, 1);\n // 이미 선택된 종료 월을 다시 클릭하면 해제\n if (\n tempDateRange?.to?.getMonth() === idx &&\n tempDateRange?.to?.getFullYear() === tempRangeEndYear\n ) {\n setTempDateRange({ from: tempDateRange?.from, to: undefined });\n } else {\n setTempDateRange({ from: tempDateRange?.from, to: newDate });\n }\n }}\n disabled={isDisabled}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n );\n })}\n </div>\n </div>\n </div>\n ) : (\n <div className=\"p-4 space-y-2\">\n <Select\n value={tempYear}\n onValueChange={(nextYear) => {\n if (nextYear !== undefined) setTempYear(nextYear);\n }}\n items={years.map((year) => ({ value: year, label: String(year) }))}\n className=\"h-8 text-xs\"\n />\n <div className=\"grid grid-cols-3 gap-2\">\n {MONTHS.map((month, idx) => (\n <Button\n key={month}\n variant={\n tempDate?.getMonth() === idx && tempDate?.getFullYear() === tempYear\n ? \"default\"\n : \"outline\"\n }\n size=\"sm\"\n onClick={() => {\n const newDate = new Date(tempYear, idx, 1);\n // 이미 선택된 월을 다시 클릭하면 해제\n if (tempDate?.getMonth() === idx && tempDate?.getFullYear() === tempYear) {\n setTempDate(undefined);\n } else {\n setTempDate(newDate);\n }\n }}\n className=\"h-8 text-xs\"\n >\n {month}\n </Button>\n ))}\n </div>\n </div>\n )}\n <div className=\"p-3 border-t flex justify-end gap-2\">\n <Button variant=\"outline\" size=\"sm\" onClick={handleCancel} className=\"h-8 text-xs\">\n {SD(\"rc.common.cancel\")}\n </Button>\n <Button variant=\"default\" size=\"sm\" onClick={handleSave} className=\"h-8 text-xs\">\n {SD(\"rc.common.save\")}\n </Button>\n </div>\n </PopoverContent>\n </Popover>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAsCA,IAAM,IAAS;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAK;AAElG,SAAgB,EAAoB,EAClC,iBACA,oBACA,UACA,kBACA,gBACA,gBAAa,YACb,eAAY,IACZ,eAAY;CAAE,OAAO;CAAM,KAAK;AA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AAK,GAAU,GAAK,CAAC;SAEzC,AAAI,GAAU,SAAS,MAAM,KAAO,GAAU,YAAY,MAAM,IAC9D,EAAY,KAAA,CAAS,IAErB,EAAY,CAAO;QAEvB;QACA,WAAU;kBAET;OACK,GAnBD,CAmBC,CACT;MACE,CAAA,CACF;;KAEP,kBAAC,OAAD;MAAK,WAAU;gBAAf,CACE,kBAAC,GAAD;OAAQ,SAAQ;OAAU,MAAK;OAAK,eA5LnB;QACzB,EAAU,EAAK;OACjB;OA0LqE,WAAU;iBAClE,EAAG,kBAAkB;MAChB,CAAA,GACR,kBAAC,GAAD;OAAQ,SAAQ;OAAU,MAAK;OAAK,eAhNrB;QACvB,IAAI;QAaJ,AAXI,KAAmB,GAAe,QAAQ,GAAe,KAC3D,IAAW;SACT,MAAM;SACN,MAAM,EAAc;SACpB,IAAI,EAAc;QACpB,IACS,CAAC,KAAmB,MAC7B,IAAW;SAAE,MAAM;SAAU,MAAM;QAAS,IAG9C,IAAgB,CAAQ,GACxB,EAAU,EAAK;OACjB;OAiMmE,WAAU;iBAChE,EAAG,gBAAgB;MACd,CAAA,CACL;;IACS;KACT;;CACN,CAAA;AAET"}
@@ -3,15 +3,16 @@ import { Button as t } from "./button.js";
3
3
  import { useSonamuBaseContext as n } from "../../contexts/sonamu-context.js";
4
4
  import * as r from "react";
5
5
  import { jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ import { isFunction as o } from "radashi";
6
7
  //#region src/components/ui/pagination.tsx
7
- var o = r.forwardRef(({ value: r, onValueChange: o, total: s, itemsPerPage: c, className: l, maxVisible: u = 6 }, d) => {
8
- let { SD: f } = n(), p = Math.ceil(s / c), m = r, h = (m - 1) * c + 1, g = Math.min(m * c, s);
8
+ var s = r.forwardRef(({ value: r, onValueChange: s, total: c, itemsPerPage: l, className: u, maxVisible: d = 6 }, f) => {
9
+ let { SD: p } = n(), m = Math.ceil(c / l), h = r, g = (h - 1) * l + 1, _ = Math.min(h * l, c), v = p("rc.pagination.showing"), y = o(v) ? v(g, _, c) : v;
9
10
  return /* @__PURE__ */ a("div", {
10
- ref: d,
11
- className: e("flex items-center justify-between pt-6", l),
11
+ ref: f,
12
+ className: e("flex items-center justify-between pt-6", u),
12
13
  children: [/* @__PURE__ */ i("div", {
13
14
  className: "text-xs text-muted-foreground",
14
- children: f("rc.pagination.showing")(h, g, s)
15
+ children: y
15
16
  }), /* @__PURE__ */ a("div", {
16
17
  className: "flex items-center gap-2",
17
18
  children: [
@@ -19,19 +20,19 @@ var o = r.forwardRef(({ value: r, onValueChange: o, total: s, itemsPerPage: c, c
19
20
  variant: "outline",
20
21
  size: "sm",
21
22
  className: "h-8 px-3 text-xs",
22
- disabled: m === 1,
23
- onClick: () => o(m - 1),
24
- children: f("rc.pagination.previous")
23
+ disabled: h === 1,
24
+ onClick: () => s(h - 1),
25
+ children: p("rc.pagination.previous")
25
26
  }),
26
27
  /* @__PURE__ */ i("div", {
27
28
  className: "flex items-center gap-1",
28
29
  children: (() => {
29
- let e = Math.max(1, m - Math.floor(u / 2)), n = Math.min(p, e + u - 1);
30
- return n - e + 1 < u && (e = Math.max(1, n - u + 1)), Array.from({ length: n - e + 1 }, (t, n) => e + n).map((e) => /* @__PURE__ */ i(t, {
30
+ let e = Math.max(1, h - Math.floor(d / 2)), n = Math.min(m, e + d - 1);
31
+ return n - e + 1 < d && (e = Math.max(1, n - d + 1)), Array.from({ length: n - e + 1 }, (t, n) => e + n).map((e) => /* @__PURE__ */ i(t, {
31
32
  variant: "outline",
32
33
  size: "sm",
33
- className: `h-8 w-8 text-xs ${e === m ? "bg-primary text-primary-foreground" : ""}`,
34
- onClick: () => o(e),
34
+ className: `h-8 w-8 text-xs ${e === h ? "bg-primary text-primary-foreground" : ""}`,
35
+ onClick: () => s(e),
35
36
  children: e
36
37
  }, e));
37
38
  })()
@@ -40,16 +41,16 @@ var o = r.forwardRef(({ value: r, onValueChange: o, total: s, itemsPerPage: c, c
40
41
  variant: "outline",
41
42
  size: "sm",
42
43
  className: "h-8 px-3 text-xs",
43
- disabled: m === p,
44
- onClick: () => o(m + 1),
45
- children: f("rc.pagination.next")
44
+ disabled: h === m,
45
+ onClick: () => s(h + 1),
46
+ children: p("rc.pagination.next")
46
47
  })
47
48
  ]
48
49
  })]
49
50
  });
50
51
  });
51
- o.displayName = "Pagination";
52
+ s.displayName = "Pagination";
52
53
  //#endregion
53
- export { o as Pagination };
54
+ export { s as Pagination };
54
55
 
55
56
  //# sourceMappingURL=pagination.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pagination.js","names":[],"sources":["../../../src/components/ui/pagination.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport { useSonamuBaseContext } from \"../../contexts\";\nimport { cn } from \"../../lib/utils\";\nimport { Button } from \"./button\";\n\nexport interface PaginationProps {\n value: number;\n onValueChange: (page: number) => void;\n total: number;\n itemsPerPage: number;\n className?: string;\n maxVisible?: number;\n}\n\nexport const Pagination = React.forwardRef<HTMLDivElement, PaginationProps>(\n ({ value, onValueChange, total, itemsPerPage, className, maxVisible = 6 }, ref) => {\n const { SD } = useSonamuBaseContext();\n const totalPages = Math.ceil(total / itemsPerPage);\n const currentPage = value;\n const startItem = (currentPage - 1) * itemsPerPage + 1;\n const endItem = Math.min(currentPage * itemsPerPage, total);\n\n return (\n <div ref={ref} className={cn(\"flex items-center justify-between pt-6\", className)}>\n <div className=\"text-xs text-muted-foreground\">\n {(\n SD(\"rc.pagination.showing\") as unknown as (\n start: number,\n end: number,\n total: number,\n ) => string\n )(startItem, endItem, total)}\n </div>\n <div className=\"flex items-center gap-2\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8 px-3 text-xs\"\n disabled={currentPage === 1}\n onClick={() => onValueChange(currentPage - 1)}\n >\n {SD(\"rc.pagination.previous\")}\n </Button>\n <div className=\"flex items-center gap-1\">\n {(() => {\n let startPage = Math.max(1, currentPage - Math.floor(maxVisible / 2));\n const endPage = Math.min(totalPages, startPage + maxVisible - 1);\n if (endPage - startPage + 1 < maxVisible) {\n startPage = Math.max(1, endPage - maxVisible + 1);\n }\n return Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i).map(\n (page) => (\n <Button\n key={page}\n variant=\"outline\"\n size=\"sm\"\n className={`h-8 w-8 text-xs ${page === currentPage ? \"bg-primary text-primary-foreground\" : \"\"}`}\n onClick={() => onValueChange(page)}\n >\n {page}\n </Button>\n ),\n );\n })()}\n </div>\n <Button\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8 px-3 text-xs\"\n disabled={currentPage === totalPages}\n onClick={() => onValueChange(currentPage + 1)}\n >\n {SD(\"rc.pagination.next\")}\n </Button>\n </div>\n </div>\n );\n },\n);\n\nPagination.displayName = \"Pagination\";\n"],"mappings":";;;;;;AAeA,IAAa,IAAa,EAAM,YAC7B,EAAE,UAAO,kBAAe,UAAO,iBAAc,cAAW,gBAAa,KAAK,MAAQ;CACjF,IAAM,EAAE,UAAO,EAAqB,GAC9B,IAAa,KAAK,KAAK,IAAQ,CAAY,GAC3C,IAAc,GACd,KAAa,IAAc,KAAK,IAAe,GAC/C,IAAU,KAAK,IAAI,IAAc,GAAc,CAAK;CAE1D,OACE,kBAAC,OAAD;EAAU;EAAK,WAAW,EAAG,0CAA0C,CAAS;YAAhF,CACE,kBAAC,OAAD;GAAK,WAAU;aAEX,EAAG,uBAAuB,EAK1B,GAAW,GAAS,CAAK;EACxB,CAAA,GACL,kBAAC,OAAD;GAAK,WAAU;aAAf;IACE,kBAAC,GAAD;KACE,SAAQ;KACR,MAAK;KACL,WAAU;KACV,UAAU,MAAgB;KAC1B,eAAe,EAAc,IAAc,CAAC;eAE3C,EAAG,wBAAwB;IACtB,CAAA;IACR,kBAAC,OAAD;KAAK,WAAU;sBACL;MACN,IAAI,IAAY,KAAK,IAAI,GAAG,IAAc,KAAK,MAAM,IAAa,CAAC,CAAC,GAC9D,IAAU,KAAK,IAAI,GAAY,IAAY,IAAa,CAAC;MAI/D,OAHI,IAAU,IAAY,IAAI,MAC5B,IAAY,KAAK,IAAI,GAAG,IAAU,IAAa,CAAC,IAE3C,MAAM,KAAK,EAAE,QAAQ,IAAU,IAAY,EAAE,IAAI,GAAG,MAAM,IAAY,CAAC,EAAE,KAC7E,MACC,kBAAC,GAAD;OAEE,SAAQ;OACR,MAAK;OACL,WAAW,mBAAmB,MAAS,IAAc,uCAAuC;OAC5F,eAAe,EAAc,CAAI;iBAEhC;MACK,GAPD,CAOC,CAEZ;KACF,GAAG;IACA,CAAA;IACL,kBAAC,GAAD;KACE,SAAQ;KACR,MAAK;KACL,WAAU;KACV,UAAU,MAAgB;KAC1B,eAAe,EAAc,IAAc,CAAC;eAE3C,EAAG,oBAAoB;IAClB,CAAA;GACL;IACF;;AAET,CACF;AAEA,EAAW,cAAc"}
1
+ {"version":3,"file":"pagination.js","names":[],"sources":["../../../src/components/ui/pagination.tsx"],"sourcesContent":["import { isFunction } from \"radashi\";\nimport * as React from \"react\";\n\nimport { useSonamuBaseContext } from \"../../contexts\";\nimport { type RCKeys } from \"../../i18n/rc-keys\";\nimport { cn } from \"../../lib/utils\";\nimport { Button } from \"./button\";\n\nexport interface PaginationProps {\n value: number;\n onValueChange: (page: number) => void;\n total: number;\n itemsPerPage: number;\n className?: string;\n maxVisible?: number;\n}\n\nexport const Pagination = React.forwardRef<HTMLDivElement, PaginationProps>(\n ({ value, onValueChange, total, itemsPerPage, className, maxVisible = 6 }, ref) => {\n const { SD } = useSonamuBaseContext<RCKeys>();\n const totalPages = Math.ceil(total / itemsPerPage);\n const currentPage = value;\n const startItem = (currentPage - 1) * itemsPerPage + 1;\n const endItem = Math.min(currentPage * itemsPerPage, total);\n const showingTranslation = SD(\"rc.pagination.showing\");\n const showingLabel = isFunction(showingTranslation)\n ? showingTranslation(startItem, endItem, total)\n : showingTranslation;\n\n return (\n <div ref={ref} className={cn(\"flex items-center justify-between pt-6\", className)}>\n <div className=\"text-xs text-muted-foreground\">{showingLabel}</div>\n <div className=\"flex items-center gap-2\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8 px-3 text-xs\"\n disabled={currentPage === 1}\n onClick={() => onValueChange(currentPage - 1)}\n >\n {SD(\"rc.pagination.previous\")}\n </Button>\n <div className=\"flex items-center gap-1\">\n {(() => {\n let startPage = Math.max(1, currentPage - Math.floor(maxVisible / 2));\n const endPage = Math.min(totalPages, startPage + maxVisible - 1);\n if (endPage - startPage + 1 < maxVisible) {\n startPage = Math.max(1, endPage - maxVisible + 1);\n }\n return Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i).map(\n (page) => (\n <Button\n key={page}\n variant=\"outline\"\n size=\"sm\"\n className={`h-8 w-8 text-xs ${page === currentPage ? \"bg-primary text-primary-foreground\" : \"\"}`}\n onClick={() => onValueChange(page)}\n >\n {page}\n </Button>\n ),\n );\n })()}\n </div>\n <Button\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8 px-3 text-xs\"\n disabled={currentPage === totalPages}\n onClick={() => onValueChange(currentPage + 1)}\n >\n {SD(\"rc.pagination.next\")}\n </Button>\n </div>\n </div>\n );\n },\n);\n\nPagination.displayName = \"Pagination\";\n"],"mappings":";;;;;;;AAiBA,IAAa,IAAa,EAAM,YAC7B,EAAE,UAAO,kBAAe,UAAO,iBAAc,cAAW,gBAAa,KAAK,MAAQ;CACjF,IAAM,EAAE,UAAO,EAA6B,GACtC,IAAa,KAAK,KAAK,IAAQ,CAAY,GAC3C,IAAc,GACd,KAAa,IAAc,KAAK,IAAe,GAC/C,IAAU,KAAK,IAAI,IAAc,GAAc,CAAK,GACpD,IAAqB,EAAG,uBAAuB,GAC/C,IAAe,EAAW,CAAkB,IAC9C,EAAmB,GAAW,GAAS,CAAK,IAC5C;CAEJ,OACE,kBAAC,OAAD;EAAU;EAAK,WAAW,EAAG,0CAA0C,CAAS;YAAhF,CACE,kBAAC,OAAD;GAAK,WAAU;aAAiC;EAAkB,CAAA,GAClE,kBAAC,OAAD;GAAK,WAAU;aAAf;IACE,kBAAC,GAAD;KACE,SAAQ;KACR,MAAK;KACL,WAAU;KACV,UAAU,MAAgB;KAC1B,eAAe,EAAc,IAAc,CAAC;eAE3C,EAAG,wBAAwB;IACtB,CAAA;IACR,kBAAC,OAAD;KAAK,WAAU;sBACL;MACN,IAAI,IAAY,KAAK,IAAI,GAAG,IAAc,KAAK,MAAM,IAAa,CAAC,CAAC,GAC9D,IAAU,KAAK,IAAI,GAAY,IAAY,IAAa,CAAC;MAI/D,OAHI,IAAU,IAAY,IAAI,MAC5B,IAAY,KAAK,IAAI,GAAG,IAAU,IAAa,CAAC,IAE3C,MAAM,KAAK,EAAE,QAAQ,IAAU,IAAY,EAAE,IAAI,GAAG,MAAM,IAAY,CAAC,EAAE,KAC7E,MACC,kBAAC,GAAD;OAEE,SAAQ;OACR,MAAK;OACL,WAAW,mBAAmB,MAAS,IAAc,uCAAuC;OAC5F,eAAe,EAAc,CAAI;iBAEhC;MACK,GAPD,CAOC,CAEZ;KACF,GAAG;IACA,CAAA;IACL,kBAAC,GAAD;KACE,SAAQ;KACR,MAAK;KACL,WAAU;KACV,UAAU,MAAgB;KAC1B,eAAe,EAAc,IAAc,CAAC;eAE3C,EAAG,oBAAoB;IAClB,CAAA;GACL;IACF;;AAET,CACF;AAEA,EAAW,cAAc"}
@@ -13,7 +13,8 @@ function r({ enum: r, labels: i, value: a, onValueChange: o, placeholder: s, tex
13
13
  ]);
14
14
  return f ? /* @__PURE__ */ n(e, {
15
15
  items: m,
16
- value: a ?? [],
16
+ valueKey: (e) => e,
17
+ value: Array.isArray(a) ? a : [],
17
18
  onValueChange: (e) => {
18
19
  o?.(e);
19
20
  },
@@ -25,7 +26,8 @@ function r({ enum: r, labels: i, value: a, onValueChange: o, placeholder: s, tex
25
26
  async: !1
26
27
  }) : /* @__PURE__ */ n(e, {
27
28
  items: m,
28
- value: a ?? "",
29
+ valueKey: (e) => e,
30
+ value: Array.isArray(a) || a === "" ? void 0 : a,
29
31
  onValueChange: (e) => {
30
32
  o?.(e);
31
33
  },
@@ -1 +1 @@
1
- {"version":3,"file":"enum-select.js","names":[],"sources":["../../../../src/components/ui/select/enum-select.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport { Select } from \"./select\";\n\n// ============================================================================\n// Type Definition\n// ============================================================================\n\n// EnumSelect Props\nexport type EnumSelectProps<TValue extends string = string> = {\n enum: { options: readonly TValue[] };\n labels: Record<TValue, string>;\n value?: TValue | TValue[] | \"\";\n onValueChange?: (value: TValue | TValue[] | \"\" | null | undefined) => void;\n placeholder?: string;\n textPrefix?: string;\n clearable?: boolean;\n disabled?: boolean;\n className?: string;\n multiple?: boolean;\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nexport function EnumSelect<TValue extends string = string>({\n enum: zodEnum,\n labels,\n value,\n onValueChange,\n placeholder,\n textPrefix = \"\",\n clearable = false,\n disabled = false,\n className,\n multiple = false,\n}: EnumSelectProps<TValue>) {\n // Zod enum에서 options 추출 (빈 문자열 필터링 - Radix UI 제약)\n const validOptions = React.useMemo(() => {\n return zodEnum.options.filter((key: unknown) => (key as string) !== \"\");\n }, [zodEnum]);\n\n // items 구성\n const items = React.useMemo(() => {\n return validOptions.map((key) => ({\n value: key as string,\n label: textPrefix + labels[key],\n }));\n }, [validOptions, labels, textPrefix]);\n\n // Single 모드\n if (!multiple) {\n return (\n <Select\n items={items}\n value={(value as TValue | \"\" | undefined) ?? \"\"}\n onValueChange={(newValue: string | undefined) => {\n onValueChange?.(newValue as TValue | \"\" | null | undefined);\n }}\n placeholder={placeholder}\n clearable={clearable}\n disabled={disabled}\n className={className}\n multiple={false}\n async={false}\n />\n );\n }\n\n // Multiple 모드\n return (\n <Select\n items={items}\n value={(value as TValue[]) ?? []}\n onValueChange={(newValue: string[]) => {\n onValueChange?.(newValue as TValue[]);\n }}\n placeholder={placeholder}\n clearable={clearable}\n disabled={disabled}\n className={className}\n multiple={true}\n async={false}\n />\n );\n}\n"],"mappings":";;;;AA0BA,SAAgB,EAA2C,EACzD,MAAM,GACN,WACA,UACA,kBACA,gBACA,gBAAa,IACb,eAAY,IACZ,cAAW,IACX,cACA,cAAW,MACe;CAE1B,IAAM,IAAe,EAAM,cAClB,EAAQ,QAAQ,QAAQ,MAAkB,MAAmB,EAAE,GACrE,CAAC,CAAO,CAAC,GAGN,IAAQ,EAAM,cACX,EAAa,KAAK,OAAS;EAChC,OAAO;EACP,OAAO,IAAa,EAAO;CAC7B,EAAE,GACD;EAAC;EAAc;EAAQ;CAAU,CAAC;CAsBrC,OAnBK,IAoBH,kBAAC,GAAD;EACS;EACP,OAAQ,KAAsB,CAAC;EAC/B,gBAAgB,MAAuB;GACrC,IAAgB,CAAoB;EACtC;EACa;EACF;EACD;EACC;EACX,UAAU;EACV,OAAO;CACR,CAAA,IA9BC,kBAAC,GAAD;EACS;EACP,OAAQ,KAAqC;EAC7C,gBAAgB,MAAiC;GAC/C,IAAgB,CAA0C;EAC5D;EACa;EACF;EACD;EACC;EACX,UAAU;EACV,OAAO;CACR,CAAA;AAoBP"}
1
+ {"version":3,"file":"enum-select.js","names":[],"sources":["../../../../src/components/ui/select/enum-select.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport { Select } from \"./select\";\n\n// ============================================================================\n// Type Definition\n// ============================================================================\n\n// EnumSelect Props\nexport type EnumSelectProps<TValue extends string = string> = {\n enum: { options: readonly TValue[] };\n labels: Record<TValue, string>;\n value?: TValue | TValue[] | \"\";\n onValueChange?: (value: TValue | TValue[] | \"\" | null | undefined) => void;\n placeholder?: string;\n textPrefix?: string;\n clearable?: boolean;\n disabled?: boolean;\n className?: string;\n multiple?: boolean;\n};\n\n// ============================================================================\n// Component\n// ============================================================================\n\nexport function EnumSelect<TValue extends string = string>({\n enum: zodEnum,\n labels,\n value,\n onValueChange,\n placeholder,\n textPrefix = \"\",\n clearable = false,\n disabled = false,\n className,\n multiple = false,\n}: EnumSelectProps<TValue>) {\n // Zod enum에서 options 추출 (빈 문자열 필터링 - Radix UI 제약)\n const validOptions = React.useMemo(() => {\n return zodEnum.options.filter((key) => key !== \"\");\n }, [zodEnum]);\n\n // items 구성\n const items = React.useMemo(() => {\n return validOptions.map((key) => ({\n value: key,\n label: textPrefix + labels[key],\n }));\n }, [validOptions, labels, textPrefix]);\n\n // Single 모드\n if (!multiple) {\n return (\n <Select\n items={items}\n valueKey={(optionValue) => optionValue}\n value={Array.isArray(value) || value === \"\" ? undefined : value}\n onValueChange={(newValue: TValue | undefined) => {\n onValueChange?.(newValue);\n }}\n placeholder={placeholder}\n clearable={clearable}\n disabled={disabled}\n className={className}\n multiple={false}\n async={false}\n />\n );\n }\n\n // Multiple 모드\n return (\n <Select\n items={items}\n valueKey={(optionValue) => optionValue}\n value={Array.isArray(value) ? value : []}\n onValueChange={(newValue: TValue[]) => {\n onValueChange?.(newValue);\n }}\n placeholder={placeholder}\n clearable={clearable}\n disabled={disabled}\n className={className}\n multiple={true}\n async={false}\n />\n );\n}\n"],"mappings":";;;;AA0BA,SAAgB,EAA2C,EACzD,MAAM,GACN,WACA,UACA,kBACA,gBACA,gBAAa,IACb,eAAY,IACZ,cAAW,IACX,cACA,cAAW,MACe;CAE1B,IAAM,IAAe,EAAM,cAClB,EAAQ,QAAQ,QAAQ,MAAQ,MAAQ,EAAE,GAChD,CAAC,CAAO,CAAC,GAGN,IAAQ,EAAM,cACX,EAAa,KAAK,OAAS;EAChC,OAAO;EACP,OAAO,IAAa,EAAO;CAC7B,EAAE,GACD;EAAC;EAAc;EAAQ;CAAU,CAAC;CAuBrC,OApBK,IAqBH,kBAAC,GAAD;EACS;EACP,WAAW,MAAgB;EAC3B,OAAO,MAAM,QAAQ,CAAK,IAAI,IAAQ,CAAC;EACvC,gBAAgB,MAAuB;GACrC,IAAgB,CAAQ;EAC1B;EACa;EACF;EACD;EACC;EACX,UAAU;EACV,OAAO;CACR,CAAA,IAhCC,kBAAC,GAAD;EACS;EACP,WAAW,MAAgB;EAC3B,OAAO,MAAM,QAAQ,CAAK,KAAK,MAAU,KAAK,KAAA,IAAY;EAC1D,gBAAgB,MAAiC;GAC/C,IAAgB,CAAQ;EAC1B;EACa;EACF;EACD;EACC;EACX,UAAU;EACV,OAAO;CACR,CAAA;AAqBP"}