develop #77

Merged
gitadmin merged 7 commits from develop into master 2026-11-19 06:59:33 +09:00
16 changed files with 2444 additions and 150 deletions

163
package-lock.json generated
View File

@@ -11,7 +11,7 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@kri/common": "^0.19.5",
"@kri/common": "^0.20.0",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -41,13 +41,14 @@
"@tiptap/starter-kit": "^3.12.0",
"class-variance-authority": "^0.7.1",
"cmdk": "^1.1.1",
"cn": "0.5.2",
"date-fns": "^4.4.0",
"dompurify": "^3.4.10",
"echarts": "^6.1.0",
"echarts-for-react": "^3.0.6",
"jotai": "^2.15.1",
"lucide-react": "^0.553.0",
"next": "^16.0.7",
"next": "^16.4.6",
"next-themes": "^0.4.6",
"prettier": "^3.9.6",
"qrcode": "^1.5.4",
@@ -60,13 +61,13 @@
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/node": "^24.19.2",
"@types/qrcode": "^1.5.6",
"@types/react": "^19",
"@types/react-dom": "^19",
"babel-plugin-react-compiler": "1.0.0",
"eslint": "^9",
"eslint-config-next": "^16.0.7",
"eslint-config-next": "^16.4.6",
"tailwindcss": "^4",
"tw-animate-css": "^1.4.0",
"typescript": "^5"
@@ -1194,14 +1195,13 @@
}
},
"node_modules/@kri/common": {
"version": "0.19.5",
"resolved": "https://gitea.kric.com/api/packages/KRi/npm/%40kri%2Fcommon/-/0.19.5/common-0.19.5.tgz",
"integrity": "sha512-Ib+fO3cak17pcRbmxME7m9XwmiWYN8LM4gA8ZhCmRvEv4dopCTY0b2qO80CJXqUybFV4jRRh50+OajANIRyw4w==",
"version": "0.20.0",
"resolved": "https://gitea.kric.com/api/packages/KRi/npm/%40kri%2Fcommon/-/0.20.0/common-0.20.0.tgz",
"integrity": "sha512-v6pLvFxePWmdSqG5cK63XwFNrmu4aiZQ1WprKktKVz9CQLpKAKPauQ2mvlQkSn70HXRaJmdwQXUpZHQBFZoE0Q==",
"license": "UNLICENSED",
"dependencies": {
"clsx": "^2.1.1",
"crypto-js": "^4.2.0",
"tailwind-merge": "^3.4.0"
"cn": "0.5.2",
"crypto-js": "^4.2.0"
},
"peerDependencies": {
"@tanstack/react-query": ">=5 <6",
@@ -1233,15 +1233,15 @@
}
},
"node_modules/@next/env": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.2.tgz",
"integrity": "sha512-nTUTFH7G5/J/fmpkjVLegOkqyKOP0CEsJcMsyO4UCYeN1su+YMW/MfaSErnJskL7XM+UDK6aTvslxsRCyya/sA==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.6.tgz",
"integrity": "sha512-SunBjJ6t+oBtecS3dTjdVuMhUogP5wD/vrGL5EVuQYM1iS4O5ilL51HkiJ3sPjMzRHiCChvr4dbaSJbR7F3lxA==",
"license": "MIT"
},
"node_modules/@next/eslint-plugin-next": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.2.tgz",
"integrity": "sha512-gCTWlw0e+Y6kajpFyKKgA195jUJCRhlzJE0lV7ufe8a+ghIsANWZ0/FiJwg6DuOG1+OvRbcZDcFBoRh3mNJx0g==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.6.tgz",
"integrity": "sha512-HdqERVOafOD8JaUSAkwf9aSu/1rsHlkN8C5GcXYBH3C/z1MxBhZFxB5rz/xqMMRiIj7r9tIv8OCLQ9JWUxCvWA==",
"dev": true,
"license": "MIT",
"dependencies": {
@@ -1250,9 +1250,9 @@
}
},
"node_modules/@next/swc-darwin-arm64": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.2.tgz",
"integrity": "sha512-ONkhFvZNFWlsEHOM/81AtxdyuJP2KRYKYR0JxPwvcu1AuPMMMgcL+wW2luldJvMtZwKtUxoSkCychW5wIeoYSw==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-16.4.6.tgz",
"integrity": "sha512-kJ4VVZkley17xKaJx72QN2IBqjrj7zenCQZaUF0l9ShS/1Mt2kW4+Z5KGG6vgr3L/J562xTOizVyM1iA/u5nlg==",
"cpu": [
"arm64"
],
@@ -1266,9 +1266,9 @@
}
},
"node_modules/@next/swc-darwin-x64": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.2.tgz",
"integrity": "sha512-luPCMbOsCoaF+kXJEUjmjmOZg1lC3BflhmUu+ZmW4tBu2vW/4AXak8JBFvePizGkxVmNiAw/r9ra+6UviCWtWQ==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-16.4.6.tgz",
"integrity": "sha512-eIPGZIqC+8JKaeZmvnCANJQF4xWkkHqSnAAajtFxgwDMAOnCgxNvP52SeWZ41PyVwoe+Le/NQuZSaQ8j7YshSA==",
"cpu": [
"x64"
],
@@ -1282,12 +1282,15 @@
}
},
"node_modules/@next/swc-linux-arm64-gnu": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.2.tgz",
"integrity": "sha512-xhwFTAncJyaCNy5KqKKuKaIIdCy1/1ZV1s5S1G0hhT7wGMkDTlfJ6aQbfRFnIG/s3/kDrxQ8aycVe+c5QnP8ow==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-16.4.6.tgz",
"integrity": "sha512-9nI6O8vvczH2D9ZNdMGqb/3NuT15T9ksOZnAmx9/gjF2cOi74+xxyf1Hk96uIMfm14c9y6wHeBq6SH8g6udvcA==",
"cpu": [
"arm64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1298,12 +1301,15 @@
}
},
"node_modules/@next/swc-linux-arm64-musl": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.2.tgz",
"integrity": "sha512-T1PNmfbPcxr5ndtWUL/3wQtLXsz808lq6sc2GrNT5k2oquF7UyqZddHSuAewHVsWsGXe6nsl9HoN1YNriVjuSg==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-16.4.6.tgz",
"integrity": "sha512-7/qPhTxDp2ScluOJOhLuhWmlA17o1yZ0SIgpISBCpBxXgtnK4+KGywBpFkfLPiU1rnSM1faFGzYkH6i7JdTrqA==",
"cpu": [
"arm64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1314,12 +1320,15 @@
}
},
"node_modules/@next/swc-linux-x64-gnu": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.2.tgz",
"integrity": "sha512-N9cDUOCGtkJG5PNKDFZUF3xXndrJJcpLp121uAGjIGvO/U2p9tfdNOM9htj7+5f72l0m8rMw/cvYacUJBQoudg==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-16.4.6.tgz",
"integrity": "sha512-oOpbNa8XOW1qCGd9VvzC4fbkkRxEls7/WI6tz+YHC0xRA7KpV1U7DrAnCPjzVyOk/karzWEepCOcTIDmwK8FwQ==",
"cpu": [
"x64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1330,12 +1339,15 @@
}
},
"node_modules/@next/swc-linux-x64-musl": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.2.tgz",
"integrity": "sha512-yY2uh1YhX6ufuYy2FCbw1dqblbhI57GLYAJfCkqD9auTv6pLrH67Uccjc3QMKBeCYAG6lkgu08ExmX1bbjejjQ==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-16.4.6.tgz",
"integrity": "sha512-aM8CZ+OR2EwXaAYw7KGkW2GDmNDsLBIRe1MMRZCJPTdw/xhTD0IMUVO4sf3KqrzuRouGzwwLZn34+gFeVXiUQA==",
"cpu": [
"x64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -1346,9 +1358,9 @@
}
},
"node_modules/@next/swc-win32-arm64-msvc": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.2.tgz",
"integrity": "sha512-j/ArWRIHpMMB6wYLMhr2puTguBt70lNU/Cmjl9p6dTDE8DGknYJMP9PdwPk2dqpCNL/KIX9yfngDvIesxJPmsg==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-16.4.6.tgz",
"integrity": "sha512-U0p7/tEtqvHX2crhd841CDwKtp5CFkKXVjOhmfccR3Pvp64sj8KBwRqsvltqLOwVBbj0NtkxwXSDpEHYGbxeXQ==",
"cpu": [
"arm64"
],
@@ -1362,9 +1374,9 @@
}
},
"node_modules/@next/swc-win32-x64-msvc": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.2.tgz",
"integrity": "sha512-AA4edyWHDko3NCSo0x6GomsdgFb0oR1J3MXU1b5xt6FRFg4AucrMPW3S0hCe/9onU0O1BbpGQBsqo1r0Gneu1g==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.4.6.tgz",
"integrity": "sha512-3ZG15/5WIdlTQsIEvc9sPTTSL5XFrlLklIKmfF4fwsDnoAhu6NcBDXsk3mbGxNyo6aVLEGex+fHCv2MahY7a9g==",
"cpu": [
"x64"
],
@@ -3811,12 +3823,13 @@
"dev": true
},
"node_modules/@types/node": {
"version": "20.19.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.25.tgz",
"integrity": "sha512-ZsJzA5thDQMSQO788d7IocwwQbI8B5OPzmqNvpf3NY/+MHDAS759Wo0gd2WQeXYt5AAAQjzcrTVC6SKCuYgoCQ==",
"version": "24.19.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.2.tgz",
"integrity": "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~6.21.0"
"undici-types": ">=7.24.0 <7.24.7"
}
},
"node_modules/@types/qrcode": {
@@ -4947,6 +4960,18 @@
"react-dom": "^18 || ^19 || ^19.0.0-rc"
}
},
"node_modules/cn": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/cn/-/cn-0.5.2.tgz",
"integrity": "sha512-wm10E6iuJ37rALOw3D+3cfaXXZSLNMh2uxpQn3dNICqfJM59yXqgbA9/9Iiz155j5kYNLdK6WreNdW3NQtx3OQ==",
"license": "MIT",
"bin": {
"cn": "bin/cn.mjs"
},
"engines": {
"node": ">=22"
}
},
"node_modules/codepage": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz",
@@ -5516,13 +5541,13 @@
}
},
"node_modules/eslint-config-next": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.2.tgz",
"integrity": "sha512-P33vjcETMXc+qBjpF77TeJHZLzk6cPcTy8KjpxLucYB3mCIFIORMcZ+cBXcAiIYjE5RM7jyknEEOwMNdnx/ADQ==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.6.tgz",
"integrity": "sha512-IBGGrVf9E6pL0NGL0hmeicVGeSyv1VEzIWq6IecDqkw+YFByhEtDJS9u1r6s6a1VxK6rssh69KyNFQUgfaacqw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@next/eslint-plugin-next": "16.4.2",
"@next/eslint-plugin-next": "16.4.6",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.32.0",
@@ -7367,12 +7392,12 @@
"dev": true
},
"node_modules/next": {
"version": "16.4.2",
"resolved": "https://registry.npmjs.org/next/-/next-16.4.2.tgz",
"integrity": "sha512-r+oBJojfefUjOiWkBhXgLS+igxX/7BWyK59uHnyOyplMSLtBZ+QLP3okrdYTbrfrbrmNTVWLBPaHDX9KRaIt3w==",
"version": "16.4.6",
"resolved": "https://registry.npmjs.org/next/-/next-16.4.6.tgz",
"integrity": "sha512-QZJiYhaZLJMo2KpkQGQIwvmd79WVsAWeYIU554a8d7zArS3si/IRy3lBNV/rtYhE70oLwdLYhPAXLPx8HwcwtA==",
"license": "MIT",
"dependencies": {
"@next/env": "16.4.2",
"@next/env": "16.4.6",
"@swc/helpers": "0.5.23",
"baseline-browser-mapping": "^2.9.19",
"caniuse-lite": "^1.0.30001579",
@@ -7386,14 +7411,14 @@
"node": ">=20.9.0"
},
"optionalDependencies": {
"@next/swc-darwin-arm64": "16.4.2",
"@next/swc-darwin-x64": "16.4.2",
"@next/swc-linux-arm64-gnu": "16.4.2",
"@next/swc-linux-arm64-musl": "16.4.2",
"@next/swc-linux-x64-gnu": "16.4.2",
"@next/swc-linux-x64-musl": "16.4.2",
"@next/swc-win32-arm64-msvc": "16.4.2",
"@next/swc-win32-x64-msvc": "16.4.2",
"@next/swc-darwin-arm64": "16.4.6",
"@next/swc-darwin-x64": "16.4.6",
"@next/swc-linux-arm64-gnu": "16.4.6",
"@next/swc-linux-arm64-musl": "16.4.6",
"@next/swc-linux-x64-gnu": "16.4.6",
"@next/swc-linux-x64-musl": "16.4.6",
"@next/swc-win32-arm64-msvc": "16.4.6",
"@next/swc-win32-x64-msvc": "16.4.6",
"sharp": "^0.35.5"
},
"peerDependencies": {
@@ -8816,15 +8841,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/tailwind-merge": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.4.0.tgz",
"integrity": "sha512-uSaO4gnW+b3Y2aWoWfFpX62vn2sR3skfhbjsEnaBI81WD1wBLlHZe5sWf0AqjksNdYTbGBEd0UasQMT3SNV15g==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/dcastil"
}
},
"node_modules/tailwindcss": {
"version": "4.1.17",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.17.tgz",
@@ -9096,10 +9112,11 @@
}
},
"node_modules/undici-types": {
"version": "6.21.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
"dev": true
"version": "7.24.6",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz",
"integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==",
"dev": true,
"license": "MIT"
},
"node_modules/unrs-resolver": {
"version": "1.11.1",

View File

@@ -12,7 +12,7 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@kri/common": "^0.19.5",
"@kri/common": "^0.20.0",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -42,13 +42,14 @@
"@tiptap/starter-kit": "^3.12.0",
"class-variance-authority": "^0.7.1",
"cmdk": "^1.1.1",
"cn": "0.5.2",
"date-fns": "^4.4.0",
"dompurify": "^3.4.10",
"echarts": "^6.1.0",
"echarts-for-react": "^3.0.6",
"jotai": "^2.15.1",
"lucide-react": "^0.553.0",
"next": "^16.0.7",
"next": "^16.4.6",
"next-themes": "^0.4.6",
"prettier": "^3.9.6",
"qrcode": "^1.5.4",
@@ -61,13 +62,13 @@
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/node": "^24.19.2",
"@types/qrcode": "^1.5.6",
"@types/react": "^19",
"@types/react-dom": "^19",
"babel-plugin-react-compiler": "1.0.0",
"eslint": "^9",
"eslint-config-next": "^16.0.7",
"eslint-config-next": "^16.4.6",
"tailwindcss": "^4",
"tw-animate-css": "^1.4.0",
"typescript": "^5"

View File

@@ -0,0 +1,247 @@
'use client'
import { useState, type CSSProperties, type KeyboardEvent } from 'react'
import { Check } from 'lucide-react'
import { Slider as SliderPrimitive } from 'radix-ui'
import { Button } from '@/components/ui/button'
import { ColorPicker, ColorPickerArea, ColorPickerHueSlider } from '@/components/common/color-palette/color-picker'
import { Input } from '@/components/ui/input'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { cn } from '@/lib/utils'
import { formatHexColor, isLightHexColor, normalizeHexColor, parseHexColor } from '@/components/common/color-palette/color'
export const KRI_COLOR_PALETTE_DEFAULT_COLORS = [
'#111827', '#4B5563', '#9CA3AF', '#E5E7EB', '#EF4444', '#F97316', '#F59E0B', '#EAB308',
'#84CC16', '#22C55E', '#14B8A6', '#06B6D4', '#3B82F6', '#6366F1', '#A855F7', '#EC4899',
] as const
const CUSTOM_PICKER_FALLBACK = '#3B82F6'
const CHECKERBOARD = 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0% 50% / 8px 8px'
export type KriColorPaletteProps = {
/** `#RRGGBB` 또는 `#RRGGBBAA` 형식의 색상. 지정되지 않았으면 null */
value: string | null
onChange: (value: string | null) => void
colors?: readonly string[]
/** 색상 영역·색조 슬라이더·HEX 입력 노출 여부 */
allowCustom?: boolean
/**
* 투명도 슬라이더 노출 및 `#RRGGBBAA` 입력 허용 여부.
* false여도 전달받은 값의 투명도는 표시·보존하며, 사용자가 색을 바꾸면 불투명(`#RRGGBB`)으로 바뀐다.
*/
allowAlpha?: boolean
allowClear?: boolean
disabled?: boolean
placeholder?: string
className?: string
'aria-label'?: string
}
const swatchStyle = (color: string): CSSProperties => ({
background: `linear-gradient(${color}, ${color}), ${CHECKERBOARD}`,
})
export function KriColorPalette({
value,
onChange,
colors = KRI_COLOR_PALETTE_DEFAULT_COLORS,
allowCustom = true,
allowAlpha = false,
allowClear = true,
disabled = false,
placeholder = '색상 없음',
className,
'aria-label': ariaLabel = '색상 선택',
}: KriColorPaletteProps) {
const normalizedValue = normalizeHexColor(value)
const parsedValue = parseHexColor(normalizedValue)
const currentAlpha = parsedValue?.alpha ?? 255
const [open, setOpen] = useState(false)
// 프리셋·HEX 입력·제거로 값이 바뀌면 색상 영역을 새 값으로 다시 초기화한다.
const [pickerKey, setPickerKey] = useState(0)
const [hexDraft, setHexDraft] = useState(normalizedValue ?? '')
const [hexDraftSource, setHexDraftSource] = useState(normalizedValue)
const [hexInvalid, setHexInvalid] = useState(false)
if (hexDraftSource !== normalizedValue) {
setHexDraftSource(normalizedValue)
setHexDraft(normalizedValue ?? '')
setHexInvalid(false)
}
const withAlpha = (rgb: string) => formatHexColor(rgb, allowAlpha ? currentAlpha : 255)
const selectDiscrete = (next: string | null) => {
onChange(next)
setPickerKey((key) => key + 1)
}
const handlePickerChange = (next: string) => {
const parsed = parseHexColor(next)
if (!parsed) return
const nextValue = withAlpha(parsed.rgb)
if (nextValue === normalizedValue) return
onChange(nextValue)
}
const handleAlphaChange = (values: number[]) => {
const percent = values[0] ?? 100
const nextValue = formatHexColor(parsedValue?.rgb ?? CUSTOM_PICKER_FALLBACK, (percent / 100) * 255)
if (nextValue === normalizedValue) return
onChange(nextValue)
}
const commitHexDraft = () => {
if (hexDraft.trim() === '') {
setHexDraft(normalizedValue ?? '')
setHexInvalid(false)
return
}
// 전달받은 값을 그대로 두고 포커스만 이동한 경우(투명도 포함 값 포함)는 변경으로 보지 않는다.
if (normalizeHexColor(hexDraft) === normalizedValue) {
setHexDraft(normalizedValue ?? '')
setHexInvalid(false)
return
}
const parsed = parseHexColor(hexDraft)
if (!parsed || (!allowAlpha && parsed.alpha !== 255)) {
setHexInvalid(true)
return
}
const nextValue = formatHexColor(parsed.rgb, parsed.alpha)
setHexInvalid(false)
setHexDraft(nextValue)
if (nextValue !== normalizedValue) selectDiscrete(nextValue)
}
const handleHexKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key !== 'Enter') return
event.preventDefault()
commitHexDraft()
}
const hexFormatLabel = allowAlpha ? '#RRGGBB 또는 #RRGGBBAA' : '#RRGGBB'
const alphaPercent = Math.round((currentAlpha / 255) * 100)
// disabled이면 트리거 상태와 무관하게 팝오버가 열리지 않도록 한다(이미 열린 상태에서 disabled로 바뀐 경우 포함).
const resolvedOpen = open && !disabled
return (
<Popover open={resolvedOpen} onOpenChange={(nextOpen) => setOpen(nextOpen && !disabled)}>
<PopoverTrigger asChild>
<Button
type="button"
variant="outline"
size="sm"
disabled={disabled}
aria-label={`${ariaLabel}: ${normalizedValue ?? placeholder}`}
className={cn('w-full justify-start gap-2 px-2 font-normal', className)}
>
<span
aria-hidden
className={cn('size-4 shrink-0 rounded-sm border', !normalizedValue && 'bg-[linear-gradient(to_bottom_right,transparent_calc(50%-1px),var(--destructive)_calc(50%-1px)_calc(50%+1px),transparent_calc(50%+1px))]')}
style={normalizedValue ? swatchStyle(normalizedValue) : undefined}
/>
<span className={cn('truncate font-mono text-xs', !normalizedValue && 'text-muted-foreground font-sans')}>
{normalizedValue ?? placeholder}
</span>
</Button>
</PopoverTrigger>
<PopoverContent align="start" className="w-64 space-y-3 p-3">
<div className="grid grid-cols-8 gap-1.5" role="group" aria-label="기본 색상">
{colors.map((color) => {
const parsedColor = parseHexColor(color)
if (!parsedColor) return null
const selected = parsedColor.rgb === parsedValue?.rgb
const checkColorClass = isLightHexColor(parsedColor.rgb) ? 'text-black' : 'text-white'
return (
<button
key={parsedColor.rgb}
type="button"
className="focus-visible:ring-ring flex size-6 items-center justify-center rounded-sm border focus-visible:ring-2 focus-visible:outline-none"
style={{ backgroundColor: parsedColor.rgb }}
aria-label={`색상 ${parsedColor.rgb}`}
aria-pressed={selected}
title={parsedColor.rgb}
onClick={() => selectDiscrete(withAlpha(parsedColor.rgb))}
>
{selected ? <Check className={cn('size-3.5', checkColorClass)} /> : null}
</button>
)
})}
</div>
{allowCustom ? (
<div className="space-y-3 border-t pt-3">
<ColorPicker
key={pickerKey}
inline
defaultValue={parsedValue?.rgb ?? CUSTOM_PICKER_FALLBACK}
onValueChange={handlePickerChange}
className="flex flex-col gap-3"
>
<ColorPickerArea className="h-32" />
<ColorPickerHueSlider aria-label="색조" />
</ColorPicker>
{allowAlpha ? (
<div className="flex items-center gap-2">
<SliderPrimitive.Root
className="relative flex w-full touch-none items-center select-none"
min={0}
max={100}
step={1}
value={[alphaPercent]}
onValueChange={handleAlphaChange}
aria-label="투명도"
>
<SliderPrimitive.Track
className="relative h-3 w-full grow overflow-hidden rounded-full"
style={{ background: CHECKERBOARD }}
>
<div
className="absolute inset-0 rounded-full"
style={{ background: `linear-gradient(to right, transparent, ${parsedValue?.rgb ?? CUSTOM_PICKER_FALLBACK})` }}
/>
</SliderPrimitive.Track>
<SliderPrimitive.Thumb className="border-primary/50 bg-background focus-visible:ring-ring block size-4 rounded-full border shadow focus-visible:ring-1 focus-visible:outline-none" />
</SliderPrimitive.Root>
<span className="text-muted-foreground w-10 shrink-0 text-right font-mono text-xs">{alphaPercent}%</span>
</div>
) : null}
<div className="space-y-1">
<Input
value={hexDraft}
onChange={(event) => {
setHexDraft(event.target.value)
setHexInvalid(false)
}}
onBlur={commitHexDraft}
onKeyDown={handleHexKeyDown}
placeholder={allowAlpha ? '#RRGGBBAA' : '#RRGGBB'}
maxLength={allowAlpha ? 9 : 7}
aria-label="HEX 색상 코드"
aria-invalid={hexInvalid}
className="h-8 font-mono text-sm"
/>
{hexInvalid ? <p className="text-destructive text-xs">{hexFormatLabel} 형식으로 입력해 주세요.</p> : null}
</div>
</div>
) : null}
{allowClear ? (
<div className="flex justify-end border-t pt-2">
<Button
type="button"
variant="ghost"
size="sm"
disabled={!normalizedValue}
onClick={() => selectDiscrete(null)}
>
색상 제거
</Button>
</div>
) : null}
</PopoverContent>
</Popover>
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
export type ParsedHexColor = {
/** `#RRGGBB` (대문자) */
rgb: string
/** 0~255. 투명도가 없는 값은 255 */
alpha: number
}
const HEX_COLOR_PATTERN = /^#?([0-9A-F]{6})([0-9A-F]{2})?$/
/** `#RRGGBB` 또는 `#RRGGBBAA`(대소문자 무관, `#` 생략 가능)를 해석한다. 형식이 다르면 null. */
export const parseHexColor = (value: string | null | undefined): ParsedHexColor | null => {
if (!value) return null
const match = HEX_COLOR_PATTERN.exec(value.trim().toUpperCase())
if (!match) return null
return {
rgb: `#${match[1]}`,
alpha: match[2] ? Number.parseInt(match[2], 16) : 255,
}
}
/** 투명도가 255이면 `#RRGGBB`, 아니면 `#RRGGBBAA`로 만든다. */
export const formatHexColor = (rgb: string, alpha = 255): string => {
const clamped = Math.max(0, Math.min(255, Math.round(alpha)))
if (clamped === 255) return rgb.toUpperCase()
return `${rgb.toUpperCase()}${clamped.toString(16).padStart(2, '0').toUpperCase()}`
}
/** 정규화된 hex 문자열. 형식이 다르면 null. */
export const normalizeHexColor = (value: string | null | undefined): string | null => {
const parsed = parseHexColor(value)
return parsed ? formatHexColor(parsed.rgb, parsed.alpha) : null
}
/** 흰 배경 위에 그렸을 때 밝은 색인지 판단한다(투명도 반영). 글자색 대비 결정에 쓴다. */
export const isLightHexColor = (value: string): boolean => {
const parsed = parseHexColor(value)
if (!parsed) return true
const ratio = parsed.alpha / 255
const channel = (offset: number) => Number.parseInt(parsed.rgb.slice(offset, offset + 2), 16) * ratio + 255 * (1 - ratio)
const luminance = (channel(1) * 299 + channel(3) * 587 + channel(5) * 114) / 1000
return luminance > 150
}

View File

@@ -0,0 +1,8 @@
import * as React from "react";
function useRefWithInit<T>(init: () => T): React.RefObject<T> {
const [ref] = React.useState(() => ({ current: init() }));
return ref;
}
export { useRefWithInit };

View File

@@ -0,0 +1,14 @@
import { useLayoutEffect } from "radix-ui/internal";
import * as React from "react";
function useValueAsRef<T>(value: T) {
const ref = React.useRef<T>(value);
useLayoutEffect(() => {
ref.current = value;
});
return ref;
}
export { useValueAsRef };

View File

@@ -0,0 +1,154 @@
"use client";
import * as React from "react";
type InputValue = string[] | string;
interface VisuallyHiddenInputProps<T = InputValue> extends Omit<
React.InputHTMLAttributes<HTMLInputElement>,
"value" | "checked" | "onReset"
> {
value?: T;
checked?: boolean;
control: HTMLElement | null;
bubbles?: boolean;
}
function VisuallyHiddenInput<T = InputValue>(
props: VisuallyHiddenInputProps<T>,
) {
const {
control,
value,
checked,
bubbles = true,
type = "hidden",
style,
...inputProps
} = props;
const isCheckInput = React.useMemo(
() => type === "checkbox" || type === "radio" || type === "switch",
[type],
);
const inputRef = React.useRef<HTMLInputElement>(null);
const prevValueRef = React.useRef<T | boolean | undefined>(
isCheckInput ? checked : value,
);
const [measuredSize, setMeasuredSize] = React.useState<{
control: HTMLElement;
width: number;
height: number;
} | null>(null);
const controlSize = React.useMemo<{
width?: number;
height?: number;
}>(
() =>
control && measuredSize?.control === control
? { width: measuredSize.width, height: measuredSize.height }
: {},
[control, measuredSize],
);
React.useLayoutEffect(() => {
if (!control) return;
if (typeof window === "undefined") return;
const resizeObserver = new ResizeObserver((entries) => {
if (!Array.isArray(entries) || !entries.length) return;
const entry = entries[0];
if (!entry) return;
let width: number;
let height: number;
if ("borderBoxSize" in entry) {
const borderSizeEntry = entry.borderBoxSize;
const borderSize = Array.isArray(borderSizeEntry)
? borderSizeEntry[0]
: borderSizeEntry;
width = borderSize.inlineSize;
height = borderSize.blockSize;
} else {
width = control.offsetWidth;
height = control.offsetHeight;
}
setMeasuredSize({ control, width, height });
});
resizeObserver.observe(control, { box: "border-box" });
return () => {
resizeObserver.disconnect();
};
}, [control]);
React.useEffect(() => {
const currentValue = isCheckInput ? checked : value;
const prevValue = prevValueRef.current;
prevValueRef.current = currentValue;
const input = inputRef.current;
if (!input) return;
const inputProto = window.HTMLInputElement.prototype;
const propertyKey = isCheckInput ? "checked" : "value";
const eventType = isCheckInput ? "click" : "input";
let serializedCurrentValue: unknown = value;
if (isCheckInput) {
serializedCurrentValue = checked;
} else if (typeof value === "object" && value !== null) {
serializedCurrentValue = JSON.stringify(value);
}
const descriptor = Object.getOwnPropertyDescriptor(inputProto, propertyKey);
const setter = descriptor?.set;
if (prevValue !== currentValue && setter) {
const event = new Event(eventType, { bubbles });
setter.call(input, serializedCurrentValue);
input.dispatchEvent(event);
}
}, [value, checked, bubbles, isCheckInput]);
const composedStyle = React.useMemo<React.CSSProperties>(() => {
return {
...style,
...(controlSize.width !== undefined && controlSize.height !== undefined
? controlSize
: {}),
border: 0,
clip: "rect(0 0 0 0)",
clipPath: "inset(50%)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: 0,
position: "absolute",
whiteSpace: "nowrap",
width: "1px",
};
}, [style, controlSize]);
return (
<input
type={type}
{...inputProps}
ref={inputRef}
aria-hidden={isCheckInput}
tabIndex={-1}
defaultChecked={isCheckInput ? checked : undefined}
style={composedStyle}
/>
);
}
export { VisuallyHiddenInput };

View File

@@ -20,6 +20,7 @@ import {
} from '@dnd-kit/sortable'
import { CSS } from '@dnd-kit/utilities'
import { GripVertical, Plus, Trash2 } from 'lucide-react'
import { KriColorPalette } from '@/components/common/KriColorPalette'
import { KriDialog } from '@/components/common/KriDialog'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
@@ -44,6 +45,7 @@ export type ListHeaderManageDialogProps = {
type ListHeaderRowProps = {
row: listHeader
activeId: number | null
onHeaderColorChange: (id: number, color: string | null) => void
onHeaderNameChange: (id: number, listHderNm: string) => void
onHeaderTypeChange: (id: number, listHderTy: ListHeaderType) => void
onFlagChange: (id: number, field: 'useColView' | 'useFilter' | 'useIntrvwerView' | 'useIntrvwerEdit', checked: boolean) => void
@@ -62,13 +64,23 @@ const isInterviewerEditDisabled = (row: listHeader) =>
row.listHderTy === ListHeaderConst.CONTACT_INTERVIEWER ||
row.listHderTy === ListHeaderConst.FIELD_INTERVIEWER
const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange, onFlagChange, onDelete }: ListHeaderRowProps) => {
const ListHeaderRow = ({
row,
activeId,
onHeaderColorChange,
onHeaderNameChange,
onHeaderTypeChange,
onFlagChange,
onDelete,
}: ListHeaderRowProps) => {
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: row.listHderId })
const canEditName = isCommonGrade(row.listHderGrad)
const canEditType = isCommonGrade(row.listHderGrad)
const canDelete = isCommonGrade(row.listHderGrad)
const canEditFlags = !isImmutableGrade(row.listHderGrad)
const canSort = isCommonGrade(row.listHderGrad)
// IMMUTABLE 헤더의 색상은 서버가 저장하지 않으므로 선택을 막는다.
const canEditColor = !isImmutableGrade(row.listHderGrad)
const style: CSSProperties = {
transform: CSS.Transform.toString(transform),
@@ -86,7 +98,7 @@ const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange,
ref={setNodeRef}
style={style}
className={cn(
'h-12 px-4 border-b last:border-b-0 grid grid-cols-[56px_1fr_150px_96px_96px_110px_110px_88px] items-center gap-2',
'h-12 px-4 border-b last:border-b-0 grid grid-cols-[56px_1fr_150px_120px_96px_96px_110px_110px_88px] items-center gap-2',
(activeId === row.listHderId || isDragging) && 'bg-muted',
)}
>
@@ -131,6 +143,12 @@ const ListHeaderRow = ({ row, activeId, onHeaderNameChange, onHeaderTypeChange,
))}
</SelectContent>
</Select>
<KriColorPalette
value={row.listHderColor ?? null}
onChange={(color) => onHeaderColorChange(row.listHderId, color)}
disabled={!canEditColor}
aria-label={`${row.listHderNm} 헤더 색상`}
/>
<div className="flex items-center gap-2 justify-center">
<Checkbox
id={`header-visible-${row.listHderId}`}
@@ -256,6 +274,16 @@ const ListHeaderManageDialog = ({
)
}
const handleHeaderColorChange = (id: number, listHderColor: string | null) => {
setLocalRows((prev) =>
prev.map((row) => {
if (row.listHderId !== id) return row
if (isImmutableGrade(row.listHderGrad)) return row
return { ...row, listHderColor }
}),
)
}
const handleHeaderNameChange = (id: number, listHderNm: string) => {
setLocalRows((prev) =>
prev.map((row) => {
@@ -302,6 +330,7 @@ const ListHeaderManageDialog = ({
useColView: true,
useIntrvwerView: false,
useIntrvwerEdit: false,
listHderColor: null,
}
return [...prev, nextRow]
@@ -388,10 +417,11 @@ const ListHeaderManageDialog = ({
</div>
<div className="rounded-md border overflow-hidden">
<div className="h-11 px-4 border-b bg-muted grid grid-cols-[56px_1fr_150px_96px_96px_110px_110px_88px] items-center gap-2 text-sm font-semibold">
<div className="h-11 px-4 border-b bg-muted grid grid-cols-[56px_1fr_150px_120px_96px_96px_110px_110px_88px] items-center gap-2 text-sm font-semibold">
<span>순서</span>
<span>헤더명</span>
<span>헤더 타입</span>
<span>헤더 색상</span>
<span>헤더 노출</span>
<span>필터 사용</span>
<span>면접원 노출</span>
@@ -413,6 +443,7 @@ const ListHeaderManageDialog = ({
key={row.listHderId}
row={row}
activeId={activeId}
onHeaderColorChange={handleHeaderColorChange}
onHeaderNameChange={handleHeaderNameChange}
onHeaderTypeChange={handleHeaderTypeChange}
onFlagChange={handleFlagChange}

View File

@@ -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,
@@ -34,12 +49,12 @@ export function KriEditorSms({
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 {
@@ -127,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 ? (

View File

@@ -39,6 +39,58 @@ import { useImageMapOverlay } from "./hooks/useImageMapOverlay";
type ViewMode = "wysiwyg" | "html";
type ToolbarEndSlotProps = Pick<KriEditorProps, "renderToolbarEnd"> & {
editor: Editor;
command: KriEditorCommand;
view: ViewMode;
};
// command는 ref를 사용하는 함수 묶음이라, 렌더 중 외부 함수에 직접 넘기면 React Compiler가
// ref 접근으로 판단한다. 별도 컴포넌트의 props로 전달해 렌더 범위를 분리한다(동작 동일).
function ToolbarEndSlot({ renderToolbarEnd, editor, command, view }: Readonly<ToolbarEndSlotProps>) {
return <>{renderToolbarEnd?.({ editor, command, view })}</>;
}
// 주입된 정제 함수가 우선이고, 없으면 sanitizeHtml 옵션에 따라 기본 정제기를 사용한다.
function sanitizeEditorHtml(
html: string,
htmlSanitizer: KriEditorProps["htmlSanitizer"],
sanitizeEnabled: boolean,
allowedCustomHtml: KriEditorProps["allowedCustomHtml"],
): string {
if (htmlSanitizer) return htmlSanitizer(html);
if (sanitizeEnabled) return sanitizeHtml(html, allowedCustomHtml);
return html;
}
function writeHtmlDraft(
draftRef: { current: string },
textareaRef: { current: HTMLTextAreaElement | null },
html: string,
): void {
draftRef.current = html;
if (textareaRef.current) textareaRef.current.value = html;
}
// 외부에서 본문이 변경된 경우에만 기존 editor 문서를 갱신한다.
function syncEditorContent(editor: Editor, value: string, optimisticHtml: string): void {
// 빈 문자열("")은 ProseMirror 스키마상 유효한 문서가 아니라 setContent가 조용히 실패해
// 이전 템플릿 본문이 그대로 남는 문제가 있었음 -> 빈 값은 빈 문단으로 정규화해서 비교/설정.
const normalizedValue = value || "<p></p>";
if (normalizedValue === editor.getHTML() || normalizedValue === optimisticHtml) return;
editor.commands.setContent(normalizedValue, {
emitUpdate: false,
parseOptions: { preserveWhitespace: "full" },
});
// resize가 활성화된 TipTap 이미지 NodeView는 노드의 src 변경을 기존 DOM에 반영하지 않는다.
// editor 전체 대신 NodeView만 다시 생성해 이미지를 갱신하고 편집 포커스는 유지한다.
if (normalizedValue.includes("<img")) {
editor.createNodeViews();
}
}
function getToolbarState(editor: Editor): ToolbarState {
const ts = editor.getAttributes("textStyle") as { fontSize?: string | null; fontFamily?: string | null; color?: string | null };
const hl = editor.getAttributes("highlight") as { color?: string | null };
@@ -70,7 +122,7 @@ function getToolbarState(editor: Editor): ToolbarState {
};
}
export function KriEditorWysiwyg(props: KriEditorProps) {
export function KriEditorWysiwyg(props: Readonly<KriEditorProps>) {
const {
label,
@@ -134,6 +186,9 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
}, [view]);
const htmlDraftRef = useRef<string>(value ?? "");
// HTML textarea는 비제어 컴포넌트다. 렌더 중 ref를 읽지 않도록, HTML 보기로 전환하는 시점의
// 초안을 state로 보관해 textarea가 마운트될 때의 초기값(defaultValue)으로만 사용한다.
const [htmlTextareaSeed, setHtmlTextareaSeed] = useState<string>(value ?? "");
const canImageUpload = Boolean(onImageUpload);
const selectionRef = useRef<{ from: number; to: number } | null>(null);
@@ -471,6 +526,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
if (viewRef.current === "wysiwyg") {
const raw = editor.getHTML();
htmlDraftRef.current = raw;
setHtmlTextareaSeed(raw);
setView("html");
// WYSIWYG에서 막 넘어온, 사용자가 직접 타이핑하지 않은 HTML이므로
@@ -492,14 +548,12 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
toast.message(compatibility.reason ?? "현재 HTML은 WYSIWYG로 전환할 수 없습니다.");
return;
}
const safe = htmlSanitizer
? htmlSanitizer(raw)
: sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw;
const safe = sanitizeEditorHtml(raw, htmlSanitizer, sanitizeHtmlOpt, allowedCustomHtml);
editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } });
flushChange(preserveEmptyParagraphs(editor.getHTML()));
setView("wysiwyg");
}, [allowedCustomHtml, editor, flushChange, getCompatibility, htmlSanitizer, sanitizeHtmlOpt]);
}, [allowedCustomHtml, editor, flushChange, getCompatibility, htmlSanitizer, sanitizeHtmlOpt, setView, setPreviewSource, setHtmlTextareaSeed]);
const formatHtmlView = useCallback(async () => {
try {
@@ -512,7 +566,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
toast.error("HTML 정렬에 실패했습니다.");
console.error(err);
}
}, [scheduleChange]);
}, [scheduleChange, setPreviewSource]);
useEffect(() => {
if (!editor) return;
@@ -544,46 +598,28 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
useEffect(() => {
setPreviewSource(value ?? "");
if (!editor) return;
if (value == null) return;
if (!editor || value == null) return;
const compatibility = getCompatibility(value);
if (showHtmlToggle && !compatibility.compatible) {
htmlDraftRef.current = value;
if (htmlTextareaRef.current) htmlTextareaRef.current.value = value;
// WYSIWYG로 손실 없이 편집할 수 없는 값은 HTML 보기로 전환해 원문을 유지한다.
if (showHtmlToggle && !getCompatibility(value).compatible) {
writeHtmlDraft(htmlDraftRef, htmlTextareaRef, value);
if (viewRef.current !== "html") {
viewRef.current = "html";
setHtmlTextareaSeed(value);
setView("html");
}
return;
}
if (viewRef.current === "html") {
if (getWysiwygCompatibility && value !== optimisticHtmlRef.current && value !== htmlDraftRef.current) {
htmlDraftRef.current = value;
if (htmlTextareaRef.current) htmlTextareaRef.current.value = value;
const isExternalChange = value !== optimisticHtmlRef.current && value !== htmlDraftRef.current;
if (getWysiwygCompatibility && isExternalChange) {
writeHtmlDraft(htmlDraftRef, htmlTextareaRef, value);
}
return;
}
// 빈 문자열("")은 ProseMirror 스키마상 유효한 문서가 아니라 setContent가 조용히 실패해
// 이전 템플릿 본문이 그대로 남는 문제가 있었음 -> 빈 값은 빈 문단으로 정규화해서 비교/설정.
const normalizedValue = value || "<p></p>";
const current = editor.getHTML();
if (normalizedValue !== current && normalizedValue !== optimisticHtmlRef.current) {
// 외부에서 본문이 변경된 경우에만 기존 editor 문서를 갱신한다.
editor.commands.setContent(normalizedValue, {
emitUpdate: false,
parseOptions: {preserveWhitespace: "full"},
});
// resize가 활성화된 TipTap 이미지 NodeView는 노드의 src 변경을 기존 DOM에 반영하지 않는다.
// editor 전체 대신 NodeView만 다시 생성해 이미지를 갱신하고 편집 포커스는 유지한다.
if (normalizedValue.includes("<img")) {
editor.createNodeViews();
}
}
syncEditorContent(editor, value, optimisticHtmlRef.current);
}, [value, editor, view, getCompatibility, getWysiwygCompatibility, showHtmlToggle]);
useEffect(() => {
@@ -648,14 +684,13 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
const previewHtml = useMemo(() => {
const preserved = preserveEmptyParagraphs(previewSource);
const sanitized = htmlSanitizer
? htmlSanitizer(preserved)
: sanitizeHtmlOpt ? sanitizeHtml(preserved, allowedCustomHtml) : preserved;
const sanitized = sanitizeEditorHtml(preserved, htmlSanitizer, sanitizeHtmlOpt, allowedCustomHtml);
const withLinkStyle = applyLinkPreviewClass(sanitized);
return transformPreviewHtml ? transformPreviewHtml(withLinkStyle) : withLinkStyle;
}, [allowedCustomHtml, htmlSanitizer, previewSource, sanitizeHtmlOpt, transformPreviewHtml]);
const imageMapOverlayBoxes = useImageMapOverlay(previewContainerRef, previewHtml);
// 이미지맵을 사용할 때만 미리보기에 <area> 영역을 표시한다.
const imageMapOverlayBoxes = useImageMapOverlay(previewContainerRef, previewHtml, enableImageMap && showPreview);
const wysiwygCompatibility = useMemo(
() => getCompatibility(view === "html" ? previewSource : (editor?.getHTML() ?? previewSource)),
@@ -704,7 +739,11 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
onAddRow={addRow}
onAddColumn={addColumn}
onDeleteTable={deleteTable}
customContent={props.renderToolbarEnd?.({ editor, command, view })}
customContent={
props.renderToolbarEnd ? (
<ToolbarEndSlot renderToolbarEnd={props.renderToolbarEnd} editor={editor} command={command} view={view} />
) : undefined
}
/>
</div>
) : null}
@@ -718,7 +757,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
<textarea
ref={htmlTextareaRef}
className="h-[220px] w-full resize-y rounded-md border bg-background p-3 font-mono text-sm outline-none"
defaultValue={htmlDraftRef.current}
defaultValue={htmlTextareaSeed}
onMouseDown={(e) => e.stopPropagation()}
onChange={(e) => {
htmlDraftRef.current = e.target.value;
@@ -730,9 +769,9 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
{...htmlTi.bindSelectionHandlers}
/>
{!wysiwygCompatibility.compatible ? (
<p className="mt-2 text-xs text-amber-700" role="status">
<output className="mt-2 block text-xs text-amber-700">
{wysiwygCompatibility.reason ?? "현재 HTML은 WYSIWYG에서 손실 없이 편집할 수 없습니다."}
</p>
</output>
) : null}
</div>
)}

View File

@@ -2,16 +2,18 @@ import { useLayoutEffect, useRef, useState } from "react"
import { computeImageMapOverlayBoxes, type ImageMapOverlayBox } from "../utils/imageMapOverlay"
// previewHtml이 바뀔 때마다(이미지 로드/리사이즈 포함) <map>/<area> 오버레이 위치를 다시 계산한다.
// enabled가 false이면 계산·관찰하지 않는다.
export function useImageMapOverlay(
containerRef: React.RefObject<HTMLElement | null>,
previewHtml: string,
enabled = true,
): ImageMapOverlayBox[] {
const [boxes, setBoxes] = useState<ImageMapOverlayBox[]>([])
const frameRef = useRef<number | null>(null)
useLayoutEffect(() => {
const container = containerRef.current
if (!container) {
if (!enabled || !container) {
setBoxes([])
return
}
@@ -40,7 +42,7 @@ export function useImageMapOverlay(
resizeObserver.disconnect()
window.removeEventListener("resize", scheduleRecompute)
}
}, [containerRef, previewHtml])
}, [containerRef, previewHtml, enabled])
return boxes
}

View File

@@ -17,6 +17,7 @@ import { formatKst } from '@kri/common'
import { isListFieldEditableForContact, isListFieldVisibleForContact } from '@/utils/listAccess'
import { substituteVariables } from '@/lib/variableSubstitution'
import { formatKoreanPhoneNumber } from '@/utils/phone'
import { isLightHexColor, normalizeHexColor } from '@/components/common/color-palette/color'
import SurveyQrDialog from '@/components/dialog/SurveyQrDialog'
import SingleMessageSendDialog from '@/components/dialog/SingleMessageSendDialog'
import { ctiClient } from '@/lib/cti/ctiClient'
@@ -52,12 +53,20 @@ export const buildInitialValues = (listHeaders: listHeader[], detail?: ListSearc
for (const header of listHeaders) {
if (header.listHderTy === ListHeaderConst.SID) continue
if (!isListFieldVisibleForContact(header)) continue
// 사용 허용은 저장 시 코드("0"/"1"/"9")로 보내야 하므로 폼 값은 코드로 둔다.
// 문자·알림톡 변수 치환은 resolveListHeaderValue의 라벨을 그대로 사용한다.
if (header.listHderTy === ListHeaderConst.IS_USE) {
values[header.listHderId] = detail?.use != null ? String(detail.use) : ''
continue
}
values[header.listHderId] = resolveListHeaderValue(header, detail)
}
return values
}
const IS_USE_OPTIONS = Object.entries(LIST_IS_USE_LABEL).map(([value, label]) => ({ value, label }))
const disabledContrastClass = 'bg-white disabled:opacity-100 disabled:text-foreground disabled:bg-muted/60'
// Input/textarea는 수정 불가 상태에서도 드래그 선택/복사가 가능해야 해서 disabled 대신 readOnly를 쓴다.
// disabled는 공용 Input 컴포넌트의 disabled:pointer-events-none 때문에 마우스 이벤트 자체를 못 받는다.
@@ -77,19 +86,27 @@ const getCallButtonTitle = (isCtiReady: boolean, isDialing: boolean, isEnding: b
return undefined
}
const FieldRow = ({ label, editable, children }: { label: string; editable?: boolean; children: ReactNode }) => (
<div className="flex items-center gap-3">
<Label
className={cn(
'w-24 shrink-0 wrap-anywhere rounded-md px-2 py-2.5 text-sm leading-snug font-bold text-foreground',
editable && 'bg-blue-100',
)}
>
{label}
</Label>
<div className="min-w-0 flex-1">{children}</div>
</div>
)
const FieldRow = ({ label, color, children }: { label: string; color?: string | null; children: ReactNode }) => {
// 헤더에 지정한 색상(투명도 포함)이 기본색보다 우선한다. 형식이 잘못된 값은 기본색으로 표시한다.
const headerColor = normalizeHexColor(color)
const isDarkHeaderColor = headerColor !== null && !isLightHexColor(headerColor)
return (
<div className="flex items-center gap-3">
<Label
className={cn(
'w-24 shrink-0 wrap-anywhere rounded-md px-2 py-2.5 text-sm leading-snug font-bold',
headerColor === null && 'bg-blue-100',
isDarkHeaderColor ? 'text-white' : 'text-foreground',
)}
style={headerColor ? { backgroundColor: headerColor } : undefined}
>
{label}
</Label>
<div className="min-w-0 flex-1">{children}</div>
</div>
)
}
const ListContactInfoPanel = ({
prjctIdx,
@@ -202,9 +219,9 @@ const ListContactInfoPanel = ({
const value = formValues[header.listHderId] ?? ''
const onChange = (next: string) => onFieldChange(header.listHderId, next)
if (header.listHderTy === ListHeaderConst.MEMO) {
if (header.listHderTy === ListHeaderConst.MEMO || header.listHderTy === ListHeaderConst.MULTILINE_TEXT) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<textarea
className={`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${readOnlyContrastClass}`}
value={value}
@@ -217,7 +234,7 @@ const ListContactInfoPanel = ({
if (header.listHderTy === ListHeaderConst.TEL_NUM) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
{/* 모바일(md 미만)은 버튼을 입력란 아래 줄로 내린다. */}
<div className="flex flex-col gap-2 md:flex-row">
<Input
@@ -271,7 +288,7 @@ const ListContactInfoPanel = ({
if (header.listHderTy === ListHeaderConst.EMAIL) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<div className="flex flex-col gap-2 md:flex-row">
<Input
value={value}
@@ -298,7 +315,7 @@ const ListContactInfoPanel = ({
if (header.listHderTy === ListHeaderConst.FILE) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<div className="flex items-center gap-2">
<div className="min-w-0 flex-1 truncate text-sm">
{value ? (
@@ -339,14 +356,14 @@ const ListContactInfoPanel = ({
if (header.listHderTy === ListHeaderConst.IS_USE) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<KriSingleSelect
items={Object.values(LIST_IS_USE_LABEL)}
items={IS_USE_OPTIONS}
value={value}
disabled={!editable}
onChange={onChange}
getValue={(item) => item}
getLabel={(item) => item}
getValue={(item) => item.value}
getLabel={(item) => item.label}
searchable={false}
preventDeselect
widthClassName="w-full"
@@ -359,7 +376,7 @@ const ListContactInfoPanel = ({
if (header.listHderTy === ListHeaderConst.CONTENT_ITEM && (header.filterContents?.length ?? 0) > 0) {
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<KriSingleSelect
items={header.filterContents ?? []}
value={value}
@@ -376,7 +393,7 @@ const ListContactInfoPanel = ({
}
return (
<FieldRow key={header.listHderId} label={header.listHderNm} editable={canEditField}>
<FieldRow key={header.listHderId} label={header.listHderNm} color={header.listHderColor}>
<Input
value={value}
readOnly={!editable}

View File

@@ -202,6 +202,17 @@ export const getListColumns = (
};
}
if (header.listHderTy === ListHeaderConst.MULTILINE_TEXT) {
return {
accessorKey: String(header.listHderId),
header: header.listHderNm,
meta: {
maxWidth: 200,
},
enableSorting: true,
};
}
return {
accessorKey: String(header.listHderId),
header: header.listHderNm,

View File

@@ -32,6 +32,8 @@ export const ListHeaderSpecificConst = {
EMAIL: 31,
FILE: 81,
CONTENT_ITEM: 91,
// 장문(여러 줄 입력 텍스트). 저장·필터·다운로드는 서버에서 일반 텍스트(99)와 같게 처리한다.
MULTILINE_TEXT: 98,
} as const;
export const ListHeaderConst = {
@@ -44,6 +46,7 @@ type ListHeaderType = (typeof ListHeaderConst)[keyof typeof ListHeaderConst];
export const LIST_HEADER_TYPE_ORDER = [
ListHeaderConst.TEXT,
ListHeaderConst.MULTILINE_TEXT,
ListHeaderConst.CONTENT_ITEM,
ListHeaderConst.TEL_NUM,
ListHeaderConst.EMAIL,
@@ -60,6 +63,7 @@ export const LIST_HEADER_TYPE_LABEL = {
[ListHeaderConst.FIELD_INTERVIEWER]: "면접원",
[ListHeaderConst.MEMO]: "중요 메모",
[ListHeaderConst.TEXT]: "일반",
[ListHeaderConst.MULTILINE_TEXT]: "장문",
[ListHeaderConst.TEL_NUM]: "전화번호",
[ListHeaderConst.EMAIL]: "이메일",
[ListHeaderConst.FILE]: "파일 업로드",

View File

@@ -121,6 +121,11 @@ export type listHeader = {
useIntrvwerView: boolean;
useIntrvwerEdit: boolean;
filterContents?: string[];
/**
* 헤더 색상(`#RRGGBB` 또는 `#RRGGBBAA`). null/빈 문자열은 기본색.
* 헤더 저장은 전체 덮어쓰기라 조회한 값을 그대로 다시 보내야 기존 색상이 유지된다.
*/
listHderColor?: string | null;
};
export type SurveyResultCondition = {