261001_01_ENH: mms 파일 미리보기 추가
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kri-ui-registry",
|
"name": "kri-ui-registry",
|
||||||
"version": "0.12.0",
|
"version": "0.13.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "KRI internal shadcn UI registry",
|
"description": "KRI internal shadcn UI registry",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ export function KriEditorSms({
|
|||||||
smsMaxBytes = 90,
|
smsMaxBytes = 90,
|
||||||
lmsMaxBytes = 2000,
|
lmsMaxBytes = 2000,
|
||||||
smsPreviewSuffix = '',
|
smsPreviewSuffix = '',
|
||||||
|
smsHasAttachment = false,
|
||||||
|
smsImages = [],
|
||||||
}: SmsEditorProps) {
|
}: SmsEditorProps) {
|
||||||
const [text, setText] = React.useState(value || '')
|
const [text, setText] = React.useState(value || '')
|
||||||
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
||||||
@@ -36,7 +38,7 @@ export function KriEditorSms({
|
|||||||
const textareaInsert = useTextareaInsert(textareaRef)
|
const textareaInsert = useTextareaInsert(textareaRef)
|
||||||
const previewText = smsPreviewSuffix ? `${text}\n${smsPreviewSuffix}` : text
|
const previewText = smsPreviewSuffix ? `${text}\n${smsPreviewSuffix}` : text
|
||||||
const byteSize = React.useMemo(() => calculateBytes(previewText), [previewText])
|
const byteSize = React.useMemo(() => calculateBytes(previewText), [previewText])
|
||||||
const messageType: 'SMS' | 'LMS' = byteSize > smsMaxBytes || Boolean(smsTitle) ? 'LMS' : 'SMS'
|
const messageType: 'SMS' | 'LMS' = byteSize > smsMaxBytes || Boolean(smsTitle) || smsHasAttachment ? 'LMS' : 'SMS'
|
||||||
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
|
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
|
||||||
|
|
||||||
const commitText = React.useCallback((next: string, immediate = false) => {
|
const commitText = React.useCallback((next: string, immediate = false) => {
|
||||||
@@ -88,11 +90,19 @@ export function KriEditorSms({
|
|||||||
<div className="mb-3 flex items-center justify-between px-2">
|
<div className="mb-3 flex items-center justify-between px-2">
|
||||||
<span className="text-xs font-medium text-gray-600">{byteSize}/{maxBytes}byte</span>
|
<span className="text-xs font-medium text-gray-600">{byteSize}/{maxBytes}byte</span>
|
||||||
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', messageType === 'LMS' ? 'bg-blue-500' : 'bg-red-500')}>
|
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', messageType === 'LMS' ? 'bg-blue-500' : 'bg-red-500')}>
|
||||||
{messageType}
|
{messageType === 'LMS' ? 'LMS/MMS' : 'SMS'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-1 flex-col overflow-hidden rounded-2xl bg-white shadow-sm">
|
<div className={cn('flex flex-1 flex-col rounded-2xl bg-white shadow-sm', smsImages.length > 0 ? 'overflow-y-auto' : 'overflow-hidden')}>
|
||||||
{smsTitle ? <div className="px-4 pt-3 pb-2 text-sm font-bold text-gray-800">{smsTitle}</div> : null}
|
{smsTitle ? <div className="px-4 pt-3 pb-2 text-sm font-bold text-gray-800">{smsTitle}</div> : null}
|
||||||
|
{smsImages.length > 0 ? (
|
||||||
|
<div className="flex shrink-0 flex-col gap-2 px-4 pt-3">
|
||||||
|
{smsImages.map((image) => (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element -- data/Object URL 미리보기라 next/image 최적화 대상이 아님
|
||||||
|
<img key={image.fileName} src={image.src} alt={image.fileName} title={image.fileName} className="w-full rounded-md object-contain" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
<textarea
|
<textarea
|
||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
className="w-full flex-1 resize-none bg-transparent p-4 text-sm leading-relaxed text-gray-700 outline-none"
|
className="w-full flex-1 resize-none bg-transparent p-4 text-sm leading-relaxed text-gray-700 outline-none"
|
||||||
@@ -105,7 +115,7 @@ export function KriEditorSms({
|
|||||||
onBlur={() => flushChange(latestTextRef.current)}
|
onBlur={() => flushChange(latestTextRef.current)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
readOnly={isSmsReadOnly}
|
readOnly={isSmsReadOnly}
|
||||||
style={{ minHeight: smsTitle ? '320px' : '360px' }}
|
style={{ minHeight: smsImages.length > 0 ? '160px' : smsTitle ? '320px' : '360px' }}
|
||||||
{...textareaInsert.bindSelectionHandlers}
|
{...textareaInsert.bindSelectionHandlers}
|
||||||
/>
|
/>
|
||||||
{smsPreviewSuffix ? (
|
{smsPreviewSuffix ? (
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ export type KriEditorFontFamilyOption = {
|
|||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type KriEditorSmsImage = {
|
||||||
|
fileName: string
|
||||||
|
src: string
|
||||||
|
}
|
||||||
|
|
||||||
export type KriEditorProps = {
|
export type KriEditorProps = {
|
||||||
onEditorReady?: (editor: Editor | HTMLTextAreaElement | null) => void
|
onEditorReady?: (editor: Editor | HTMLTextAreaElement | null) => void
|
||||||
onCommandReady?: (command: KriEditorCommand | null) => void
|
onCommandReady?: (command: KriEditorCommand | null) => void
|
||||||
@@ -80,6 +85,10 @@ export type KriEditorProps = {
|
|||||||
smsMaxBytes?: number
|
smsMaxBytes?: number
|
||||||
lmsMaxBytes?: number
|
lmsMaxBytes?: number
|
||||||
smsPreviewSuffix?: string
|
smsPreviewSuffix?: string
|
||||||
|
/** 첨부파일이 있으면 길이·제목과 무관하게 LMS/MMS로 판정한다. */
|
||||||
|
smsHasAttachment?: boolean
|
||||||
|
/** 문자 미리보기의 제목과 본문 사이에 표시할 첨부 이미지 */
|
||||||
|
smsImages?: KriEditorSmsImage[]
|
||||||
toolbar?: KriEditorToolbarConfig | false
|
toolbar?: KriEditorToolbarConfig | false
|
||||||
fontFamilyOptions?: KriEditorFontFamilyOption[]
|
fontFamilyOptions?: KriEditorFontFamilyOption[]
|
||||||
renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode
|
renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode
|
||||||
|
|||||||
Reference in New Issue
Block a user