261117_02_ENH: kri-editor 이미지맵 미리보기 오버레이·smsFrameClassName 추가, React Compiler lint 및 SonarQube 지적 사항 수정
This commit is contained in:
@@ -8,10 +8,25 @@ import { useTextareaInsert } from './hooks/useTextareaInsert'
|
||||
|
||||
type SmsEditorProps = Omit<KriEditorProps, 'mode'> & { mode: 'sms' }
|
||||
|
||||
type SmsMessageType = 'SMS' | 'LMS' | 'MMS'
|
||||
|
||||
function calculateBytes(value: string): number {
|
||||
return new TextEncoder().encode(value).byteLength
|
||||
}
|
||||
|
||||
// 첨부파일이 있으면 MMS, 제목이 있거나 smsMaxBytes 이상이면 LMS, 나머지는 SMS로 미리보기 판정한다.
|
||||
function getSmsMessageType(hasAttachment: boolean, byteSize: number, smsMaxBytes: number, title: string): SmsMessageType {
|
||||
if (hasAttachment) return 'MMS'
|
||||
if (byteSize >= smsMaxBytes || Boolean(title)) return 'LMS'
|
||||
return 'SMS'
|
||||
}
|
||||
|
||||
function getTextareaMinHeight(hasImages: boolean, hasTitle: boolean): string {
|
||||
if (hasImages) return '160px'
|
||||
if (hasTitle) return '320px'
|
||||
return '360px'
|
||||
}
|
||||
|
||||
export function KriEditorSms({
|
||||
label,
|
||||
value,
|
||||
@@ -29,16 +44,17 @@ export function KriEditorSms({
|
||||
smsPreviewSuffix = '',
|
||||
smsHasAttachment = false,
|
||||
smsImages = [],
|
||||
smsFrameClassName,
|
||||
}: SmsEditorProps) {
|
||||
const [text, setText] = React.useState(value || '')
|
||||
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
||||
const latestTextRef = React.useRef(text)
|
||||
const lastTypeRef = React.useRef<'SMS' | 'LMS' | 'MMS' | null>(null)
|
||||
const lastTypeRef = React.useRef<SmsMessageType | null>(null)
|
||||
const { scheduleChange, flushChange } = useDebouncedChange(onChange, debounceMs)
|
||||
const textareaInsert = useTextareaInsert(textareaRef)
|
||||
const previewText = smsPreviewSuffix ? `${text}\n${smsPreviewSuffix}` : text
|
||||
const byteSize = React.useMemo(() => calculateBytes(previewText), [previewText])
|
||||
const messageType: 'SMS' | 'LMS' | 'MMS' = smsHasAttachment ? 'MMS' : byteSize >= smsMaxBytes || Boolean(smsTitle) ? 'LMS' : 'SMS'
|
||||
const messageType = getSmsMessageType(smsHasAttachment, byteSize, smsMaxBytes, smsTitle)
|
||||
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
|
||||
|
||||
function getBadgeColor(): string {
|
||||
@@ -95,7 +111,7 @@ export function KriEditorSms({
|
||||
return (
|
||||
<div className={cn('mx-auto w-full max-w-[320px]', className)}>
|
||||
{label ? <div className="mb-2 text-sm font-semibold">{label}</div> : null}
|
||||
<div className="relative h-[600px] w-full overflow-hidden rounded-[40px] border-8 border-gray-800 bg-white shadow-2xl">
|
||||
<div className={cn('relative h-[600px] w-full overflow-hidden rounded-[40px] border-8 border-gray-800 bg-white shadow-2xl', smsFrameClassName)}>
|
||||
<div className="absolute top-0 left-1/2 z-10 h-6 w-32 -translate-x-1/2 rounded-b-2xl bg-gray-800" />
|
||||
<div className="flex h-full flex-col bg-gray-50 px-4 pt-8 pb-4">
|
||||
<div className="mb-3 flex items-center justify-between px-2">
|
||||
@@ -126,7 +142,7 @@ export function KriEditorSms({
|
||||
onBlur={() => flushChange(latestTextRef.current)}
|
||||
placeholder={placeholder}
|
||||
readOnly={isSmsReadOnly}
|
||||
style={{ minHeight: smsImages.length > 0 ? '160px' : smsTitle ? '320px' : '360px' }}
|
||||
style={{ minHeight: getTextareaMinHeight(smsImages.length > 0, Boolean(smsTitle)) }}
|
||||
{...textareaInsert.bindSelectionHandlers}
|
||||
/>
|
||||
{smsPreviewSuffix ? (
|
||||
|
||||
Reference in New Issue
Block a user